我創造了這個代碼: (AccActivity.java)AccessibilityService
package bad.android.acc;
import android.app.Activity;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class AccActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button ok = (Button)findViewById(R.id.button1);
}
public void lunch(View v) {
Log.d("TAS", "OnClick");
}
}
和(Access.java) - 擴展AccessibilityService
import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.Context;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
public class Access extends AccessibilityService{
private static final long EVENT_NOTIFICATION_TIMEOUT_MILLIS = 50;
@Override
public void onAccessibilityEvent(AccessibilityEvent arg0) {
// TODO Auto-generated method stub
Log.d("TAS", "onAccessibilityEvent");
}
@Override
public void onInterrupt() {
// TODO Auto-generated method stub
Log.d("TAS", "onInterrupt");
}
@Override
protected void onServiceConnected(){
// TODO Auto-generated method stub
Log.d("TAS", "onServiceConnected");
setServiceInfo();
}
private void setServiceInfo() {
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
// We are interested in all types of accessibility events.
info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
// We want to provide specific type of feedback.
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
// We want to receive events in a certain interval.
info.notificationTimeout = EVENT_NOTIFICATION_TIMEOUT_MILLIS;
// We want to receive accessibility events only from certain packages.
info.packageNames = new String[1];
// only handle this package
info.packageNames[0] = getPackageName();
setServiceInfo(info);
}
}
和清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="bad.android.acc"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".AccActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".Access">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
</service>
</application>
</manifest>
現在,如何啓動服務可訪問性「Access.java」?作爲正常的服務?我有點困惑與此服務.. 感謝
謝謝,我明白了,我已經解決了。我無法弄清楚如何將服務作爲MIUI打開,因爲菜單「輔助功能」已被隱藏。 –