gpt4 book ai didi

java - 启用我的 AccessibilityService 后未调用 onServiceConnected

转载 作者:行者123 更新时间:2023-11-29 02:38:29 28 4
gpt4 key购买 nike

在我打开我的应用程序后,它会跳转到辅助功能设置。但是在我打开我的 AccessibilityService(称为 VoiceService)后,onServiceConnected 没有被调用。

你能告诉我我该怎么做吗?尽管我在 XML 中启用了 VoiceService,但它似乎无法启动。或者我需要以不同的方式将 MainActivityVoiceService 绑定(bind)?

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.wang.hearexpr">
<uses-permission
android:enabled="true"
android:name="android.permission.BIND_ACCESSIBILITY_SERVICE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
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=".VoiceService"
android:enabled="true"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
android:label="@string/service_name">
<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/voice_config"/>
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService"/>
</intent-filter>

</service>

</application>
</manifest>

voice_config.xml

<?xml version="1.0" encoding="utf-8"?>
<accessibility-service
xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/service_description"
android:packageNames="com.example.wang.hearexpr"
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFlags="flagDefault"
android:accessibilityFeedbackType="feedbackSpoken"
android:notificationTimeout="100"
android:canRetrieveWindowContent="true"
android:canRequestTouchExplorationMode="true"
android:settingsActivity="com.example.android.accessibility.ServiceSettingsActivity"/>

语音服务.java

package com.example.wang.hearexpr;
import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.Intent;
import android.os.Handler;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;

public class VoiceService extends AccessibilityService {
private static final String TAG = "hear the voice";
@Override
public void onServiceConnected(){
super.onServiceConnected();
Log.d(TAG, "Service Connected");
}

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
Log.d(TAG,"onAccessibilityEvent: "+ event.toString());
}
@Override
public void onInterrupt() {
Log.d(TAG, "Interrupted");
}
@Override
public void onDestroy(){
Log.d(TAG, "Destroyed");
}
}

MainActivity.java

package com.example.wang.hearexpr;

import android.content.Intent;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {
private static final Intent sSettingsIntent =
new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startActivityForResult(sSettingsIntent,0);
}
}

最佳答案

这是答案:在 voice_config.xml

android:settingsActivity="com.example.android.accessibility.ServiceSettingsActivity" 应修改为您自己的 Activity 名称。

关于java - 启用我的 AccessibilityService 后未调用 onServiceConnected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45678878/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com