gpt4 book ai didi

android - 无障碍服务说明

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:50:57 25 4
gpt4 key购买 nike

我写了一个非常简单的 accessibilityService 并且我试图在 Settings/accessibility/my app 中显示该服务的描述。下面是我的所有代码,应该将描述设置为“你好!”但设置仍然显示“没有可用的描述”

enter image description here

我的服务:

public class IdleService extends AccessibilityService{

int interval = 100;
int maxIdleTime = 20000;
int idleTime = 0;
Handler mHandler;
String cProcess;

@Override
public void onServiceConnected(){

mHandler = new Handler();

AccessibilityServiceInfo info = new AccessibilityServiceInfo();
// we are interested in all types of accessibility events
info.describeContents();
info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
// we want to receive events in a certain interval
info.notificationTimeout = interval;

setServiceInfo(info);

Log.e("IdleService", " idle service connected!");
statusChecker.run();
}

@Override
public void onAccessibilityEvent(AccessibilityEvent arg0)
{
// TODO Auto-generated method stub
Log.v("IdleService", "reseting idle time");
idleTime = 0;
}

@Override
public void onInterrupt()
{
// TODO Auto-generated method stub
Log.v("IdleService", "INTERUPTED");
}

public void setMaxIdleTimeInSeconds(int time)
{

maxIdleTime = time *1000;
}


Runnable statusChecker = new Runnable()
{

@Override
public void run() {
// TODO Auto-generated method stub
ActivityManager am = (ActivityManager) getApplicationContext()
.getSystemService(Context.ACTIVITY_SERVICE);

List<ActivityManager.RunningTaskInfo> processList = am
.getRunningTasks(5);

cProcess = processList.get(0).baseActivity.getPackageName();

Log.v("IdleService", "Current PackageName:"+cProcess);
cProcess = processList.get(0).baseActivity.getClassName();

Log.v("IdleService", "Current ClassName:"+cProcess);
idleTime +=100;
Log.v("IdleService", "TICK TOCK, user Idle for:"+idleTime);
if(idleTime>=maxIdleTime)
{
Log.v("IdleService", "we timed out do to inactivity");
//mHandler.postDelayed(statusChecker, interval);
//stopSelf();
}else{


}
mHandler.postDelayed(statusChecker, interval);
}


};
}

在我的 list 中我有这个服务:

<service android:name="com.myPackage.IdleService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/accessibility_service_config" />
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>

</service>

在我的 res/xml 中有一个 accessibility_service_config.xml 文件:

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/accessibility_service_description"

android:settingsActivity="com.example.android.accessibility.ServiceSettingsActivity"
/>

最后在我的 res/values/中有 strings.xml,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="accessibility_service_description">Hello!</string>
</resources>

最佳答案

我遇到了同样的问题并最终解决了这个问题。我知道服务本身包含权限,但您需要添加 BIND_ACCESSIBILITY_SERVICE对 list 的许可。

<manifest ...>
...
<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />
...
</manifest>

<meta-data>服务必须命名为 android.accessibilityservice你有,所以很好。

最后,我不得不将 apk 推送到我的设备,然后重新启动它以使更改生效。

注意: 添加 description <service> 中的属性 list 中的元素不会影响系统设置中显示的服务描述。

关于android - 无障碍服务说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19274154/

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