2011-10-24 65 views
2

我創造了這個代碼: (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」?作爲正常的服務?我有點困惑與此服務.. 感謝

回答

1

「無障礙」是隱藏在MIUI,你應該按「搜索」按鈕,進入「無障礙」 (也許在中文「輔助功能」),然後你可以打開它。

0

正如我理解你的問題,似乎你想打開輔助功能設置。

如果是的話,下面的代碼啓動輔助功能設置:

Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS); 
startActivityForResult(intent, 0); 
相關問題