Я создал этот код: (AccActivity.java)
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);
}
}
и Manifest:
<?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>
Теперь, как мне запустить сервис accessibilty "Access.java"?как обычный сервис?Я немного запутался с этим сервисом .. спасибо