Java 我可以使用易访问性服务(android)从主屏幕接收信息吗?
首先,如果我没有按照这里的规则正确书写,我想道歉,我是个新手。 我需要一些帮助。 我正在尝试为我的项目构建一个应用程序,我正在尝试先做基本的工作。 我需要从用户与他的手机的交互中获取一些参数,我需要在用户退出应用程序时(在主屏幕中)实现这一点。 我一直在寻找方法,发现无障碍服务应该是有效的(我希望我没有错)。我创建了一个应用程序,但它不工作,什么也没发生。我在网上到处找,什么也找不到。这是我的密码:Java 我可以使用易访问性服务(android)从主屏幕接收信息吗?,java,android,android-studio,Java,Android,Android Studio,首先,如果我没有按照这里的规则正确书写,我想道歉,我是个新手。 我需要一些帮助。 我正在尝试为我的项目构建一个应用程序,我正在尝试先做基本的工作。 我需要从用户与他的手机的交互中获取一些参数,我需要在用户退出应用程序时(在主屏幕中)实现这一点。 我一直在寻找方法,发现无障碍服务应该是有效的(我希望我没有错)。我创建了一个应用程序,但它不工作,什么也没发生。我在网上到处找,什么也找不到。这是我的密码: package com.example.AccessibilityService; impor
package com.example.AccessibilityService;
import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.FingerprintGestureController;
import android.os.Build;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.widget.Toast;
import androidx.annotation.RequiresApi;
public class MyAccessibilityService extends AccessibilityService {
private FingerprintGestureController gestureController;
private FingerprintGestureController
.FingerprintGestureCallback fingerprintGestureCallback;
private boolean mIsGestureDetectionAvailable;
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
if (fingerprintGestureCallback != null
|| !mIsGestureDetectionAvailable) {
return;
}
fingerprintGestureCallback =
new FingerprintGestureController.FingerprintGestureCallback() {
@Override
public void onGestureDetected(int gesture) {
switch (gesture) {
case GESTURE_SWIPE_DOWN:
Toast.makeText(MyAccessibilityService.this,"swipe down occurred",Toast.LENGTH_LONG).show();
break;
case GESTURE_SWIPE_LEFT:
Toast.makeText(MyAccessibilityService.this,"swipe left occurred",Toast.LENGTH_LONG).show();
break;
case GESTURE_SWIPE_RIGHT:
Toast.makeText(MyAccessibilityService.this,"swipe right occurred",Toast.LENGTH_LONG).show();
break;
case GESTURE_SWIPE_UP:
Toast.makeText(MyAccessibilityService.this,"swipe up occurred",Toast.LENGTH_LONG).show();
break;
default:
break;
}
}
@Override
public void onGestureDetectionAvailabilityChanged(boolean available) {
mIsGestureDetectionAvailable = available;
}
};
if (fingerprintGestureCallback != null) {
gestureController.registerFingerprintGestureCallback(
fingerprintGestureCallback, null);
}
}
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onCreate() {
gestureController = getFingerprintGestureController();
mIsGestureDetectionAvailable =
gestureController.isGestureDetectionAvailable();
if(mIsGestureDetectionAvailable == true)
Toast.makeText(MyAccessibilityService.this,"working",Toast.LENGTH_LONG).show();
else
Toast.makeText(MyAccessibilityService.this,"Not working",Toast.LENGTH_LONG).show();
}
@Override
public void onInterrupt() {
}
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
protected void onServiceConnected() {
Log.d("MY_APP_TAG", "hi1234124");
}
}
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.AccessibilityService">
<uses-permission android:name="android.permission.USE_FINGERPRINT"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".MyAccessibilityService"
android:enabled="true"
android:exported="true"
android:label="My application"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibility"
android:resource="@layout/service_config" />
</service>
</application>
</manifest>
大家好,欢迎来到SO。我们需要更多的信息来帮助你。应用程序是否会进入黑屏?它会崩溃吗?谢谢你的欢迎:-)它不会崩溃,也不会出现在黑屏上。我有一个main(它是项目创建时的基本main,我没有在这里发布)。您还需要其他相关信息吗?感谢您的回复:-)代码中没有显示,但在我的代码中显示我授予的“使用指纹”权限已被否决。此问题包含太多信息。尝试并创建一个最小的可复制示例,如下所述
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<accessibility-service
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFeedbackType="feedbackAllMask"
android:accessibilityFlags="flagDefault"
android:canRequestEnhancedWebAccessibility="true"
android:canRequestTouchExplorationMode="true"
android:canRetrieveWindowContent="true"
android:notificationTimeout="100"
android:packageNames="@null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
11/14/2020
9:15 PM * daemon not running; starting now at tcp:5037
9:15 PM * daemon started successfully
9:16 PM Gradle sync started
9:16 PM Gradle sync finished in 7 s 808 ms (from cached state)
9:16 PM Android Studio 4.1.1 available
Update...
9:17 PM Executing tasks: [:app:assembleDebug] in project C:\Users\rami\AndroidStudioProjects\AccessibilityService
9:18 PM Gradle build finished in 1 m 10 s 421 ms
9:19 PM Install successfully finished in 17 s 624 ms.
9:19 PM Emulator: [6172:6468:1114/211932.545:ERROR:block_files.cc(111)] Failing CreateMapBlock
9:19 PM Emulator: [6172:6468:1114/211932.545:ERROR:entry_impl.cc(985)] Failed to save user data
9:19 PM Emulator: [6172:6468:1114/211933.355:ERROR:backend_impl.cc(1065)] Critical error found -8
9:19 PM Emulator: [6172:6468:1114/211933.356:ERROR:entry_impl.cc(1062)] No file for c1030182
9:19 PM Emulator: [6172:6468:1114/211933.386:ERROR:entry_impl.cc(1062)] No file for b102001e
9:19 PM Emulator: [6172:6468:1114/211933.387:ERROR:entry_impl.cc(1062)] No file for b302002c