How to Use Accessory Agent Service with D22 and Q3 Devices: Difference between revisions

From wizarPOS
(Replaced content with "{{Migrating|https://smartpossdk.gitbook.io/cloudpossdk/faq/usb-serial-port/accessory-agent-service-d22-q3}}")
Tag: Replaced
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
== Introduction ==
{{Migrating|https://smartpossdk.gitbook.io/cloudpossdk/faq/usb-serial-port/accessory-agent-service-d22-q3}}
D22 can connect with Q3 via USB cable. The D22 works in master mode and the Q3 works in slave mode. By the helping of the AccessoryConnectionAgent apk, the application in two terminals can send Intent to any other application in another terminal.
 
== User Manual ==
[http://ftp.wizarpos.com/advanceSDK/AccessoryConnectAgentusermanual.pdf Accessory Connection Agent service user manual]
 
== Demo ==
Demo for APK developing.
[http://ftp.wizarpos.com/advanceSDK/AccessoryAgentDemo.zip Demo]
 
[http://ftp.wizarpos.com/advanceSDK/AccessoryConnectionAgentDemo.apk APK for testing, after install and run it, it will send intent through by the USB connection to the other device, to start the merchant self test apk]
 
'''Sender snippet code:'''
<syntaxhighlight lang="java">
@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);
    }
</syntaxhighlight>
 
'''Receiver(com.wizarpos.accessoryreceiveintentdemo) snippet code:'''
<syntaxhighlight lang="java">
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //Receive intent data
        String extraData = getIntent().getStringExtra("extraData");
    }
 
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        //Receive intent data
        String extraData = intent.getStringExtra("extraData");
    }
</syntaxhighlight>
 
 
== AccessoryConnectionAgent Service APK ==
By default, the AccessoryConnectAgent is included in the D22 and Q3 FW. But it maybe not exists in the old FW, so the developer should install the agent by themselves.
Here is the agent apk:
 
[http://ftp.wizarpos.com/advanceSDK/AccessoryAgentHostService-master-release-v1.0.22-r20230825095655-q1_platform.apk Connection Agent APK]
 
== Init USB Connection Mode in Development==
By default, the AccessoryConnectionAgent is disabled, the developer can use this apk to enable it.<br>
For the production FW, the agent will be initialized before releasing from factory.
Please download and install to D22 and Q3.
 
[http://ftp.wizarpos.com/advanceSDK/InitConnectionMode.apk Initialize Initialize APK]
* Selection Mode
in Q3, default is slave, other devcies default is master mode.
* Usbchannel Switch
enable or disable the Accessory Connection Agent service

Latest revision as of 08:29, 7 April 2024

Please visit new link of same subject:

https://smartpossdk.gitbook.io/cloudpossdk/faq/usb-serial-port/accessory-agent-service-d22-q3

We're making a move! Our site's content is migrating to a new URL, to provide you with an enhanced browsing experience. Please update your bookmarks accordingly. Thank you for your continuous support!