Accessory Agent Service D22/Q3
Introduction
User Manual
Demonstration and Development:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
bindServer();
}
private void initView() {
bindServerStatus = findViewById(R.id.bindServerStatus);
startActivity = findViewById(R.id.startActivity);
String json ="{\n" +
" \"action\": \"android.intent.action.MAIN\",\n" +
" \"className\": \"com.wizarpos.accessoryreceiveintentdemo.MainActivity\",\n" +
" \"flags\": 268435456,\n" +
" \"packageName\": \"com.wizarpos.accessoryreceiveintentdemo\",\n" +
" \"putExtra\": {\n" +
" \"extraData\": \"10\"\n" +
" }\n" +
"}";
startActivity.setOnClickListener(v -> {
if(remoteServe != null){
try {
remoteServe.remoteIntent(json);
} catch (RemoteException e) {
throw new RuntimeException(e);
}
}else {
Toast.makeText(this, "The AIDL service is disconnected", Toast.LENGTH_SHORT).show();
}
});
}
private void bindServer() {
Intent intent = new Intent();
ComponentName componentName =new ComponentName(INTENT_PACKAGE, INTENT_ACTION);
intent.setComponent(componentName);
bindService(intent, mServiceConnection, BIND_AUTO_CREATE);
}
ServiceConnection mServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
remoteServe = IRemoteAccessoryApi.Stub.asInterface(service);
bindServerStatus.setText("The AIDL service is Connected");
}
@Override
public void onServiceDisconnected(ComponentName name) {
remoteServe = null;
bindServerStatus.setText("The AIDL service is disconnected");
}
};
@Override
protected void onDestroy() {
super.onDestroy();
unbindService(mServiceConnection);
}AccessoryConnectionAgent Service APK
Initiating USB Connection Mode in Development:
Test APKs between D3 and Q3
Choose Your Best Practice
Last updated