Development Tips

Unbinding QPair Service after finishing calling QPair APIs

 

Issue

In the class which implements ServiceConnection, it might cause an IllegalArgumentException that you try to call QPair APIs after you executedonServiceConnected() without unbinding QPair service.

 

Solution

You should call unbindService() in order to unbind QPair service, right after finishing calling QPair APIs as follows.

public class QPairSampleServiceConnection implements ServiceConnection {
        private IPeerContext iPeerContext = null;

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            iPeerContext = IPeerContext.Stub.asInterface(service);
            IPeerIntent peerIntent;

            try {
                peerIntent = iPeerContext.newPeerIntent();
                peerIntent.setType("image/*");
                peerIntent.setAction(Intent.ACTION_VIEW);
                iPeerContext.startActivityOnPeer(peerIntent, null);
            } catch (RemoteException e) {
                e.printStackTrace();
            }

            // unbind the QPair service. 
            unbindService(this);         ①
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            iPeerContext = null;
        }
}

 

Failing in executing startServiceOnPeerWithFile()

 

Issue #1

When you send a file to peer device with the startServiceOnPeerWithFile() method, you might fail in executing it if there is already a file with the same name on the peer device’s target directory.

 

Solution #1

You can create an unique file name by appending Timestamp to a file name. Or, you should check that there is a file of the same name before sending a file.

 

Issue #2

When you send a file to peer device with the startServiceOnPeerWithFile() method, the API does not work without any response.

 

Solution #2

If you pass null for callbacks in startServiceOnPeerWithFile(), QPair cannot send the file and cannot start the service. You must set callbacks instartServiceOnPeerWithFile().

 

Failing in setting properties of the peer device

 

Issue

Although you set peer device’s properties using in AndroidManifels.xml, it does not affect the peer device.

 

Solution

It might be because you use the wrong key string which does not conform to the URI rules. Make sure that the android:name attribute in is appropriate, especially, the package name should be the same with that of the client application.

{location(local|peer)}/{client package}/{key name}

 

Making a phone and a tablet do different actions using a single apk

 

Issue

Some QPair-enabled applications provide separate apk files for each device to do different actions depending on the device type (phone or table). However, it is better to provide a single apk file for maintenance. To do this, you need to determine whether the device is a phone or a tablet and then branch the code.

 

Solution #1 Using QPair APIs.

Determine whether the device type is a phone or a tablet by using the following QPair property:

QPairConstants.PROPERTY_SCHEME_AUTHORITY + “/local/qpair/device_type

 

For the detailed information about QPair properties, see Monitoring Property Changes.

 

Solution #2 Using Android APIs

Determine whether the device is LG G Pad by using the following API:

android.os.Build.MODEL

android.os.Build.MODEL tells you the model number of the device.

Model numbers of LG G Pad launched in 2013 and 2014 are:

• LG-V700n

• LG-V480n

• LG-V400

• LG-V500

Handling exceptions depending on the status of the QPair application

 

Issue

QPair-enabled applications work with QPair application. Therefore you must handle various exceptions that can be occurred depending on QPair application’s condition.

 

The exceptions you have to handle are:

1) When the QPair application is not installed on the user’s device

2) When your application cannot get the permission of QPair

3) When the version of the QPair application is old

4) When user does not connect his or her phone and tablet via the QPair application

 

Solution

1) When the QPair application is not installed on the user’s device

Determine whether the QPair application is installed by using the following API:

PackageManager.getInstalledPackages()

QPairConstants.PACKAGE_NAME

 

PackageManager.getInstalledPackages() returns all the installed packages on the device. You can compare QPairConstants.PACKAGE_NAME with each item in the result as follows:

 

private boolean isInstalledQPair() {
    List pInfo = getPackageManager().getInstalledPackages(0);
    for(int i = 0; i < pInfo.size(); i++) {
        if(QPairConstants.PACKAGE_NAME.equals(pInfo.get(i).packageName))
            return true;
    }
    Toast.makeText(mContext,
            "The QPair is NOT INSTALLED on your device, "
            + "so this app has stopped. Install the QPair "
            + "from Google Play.",
            Toast.LENGTH_LONG).show();
    return false;
}

 

It is better to open the installation page of the QPair application (https://play.google.com/store/apps/details?id=com....) if the device has no QPair package.

 

2) When your application cannot get the permission of QPair

A QPair-enabled application gets the permission of QPair when installed. However, if the QPair application is not installed on the device, the application cannot get the permission. In this case, users have to re-install the application after installing the QPair application.

 

Determine whether your application gets the permission of QPair by using the following APIs:

Context.checkCallingOrSelfPermission()

PackageManager.PERMISSION_GRANTED

• "com.lge.qpair.permission.USE_QPAIR_SERVICE"

 

Context.checkCallingOrSelfPermission() returns PackageManager.PERMISSION_GRANTED if the application got the specific permission. You can call the method with “com.lge.qpair.permission.USE_QPAIR_SERVICE” as follows:

 

private boolean hasQPairPermisison() {
    String permission = "com.lge.qpair.permission.USE_QPAIR_SERVICE";
   
    if(mContext.checkCallingOrSelfPermission(permission) == PackageManager.PERMISSION_GRANTED) {
        return true;
    }
     
    Toast.makeText(mContext,
      "This app is DENIED to the QPair PERMISSION, " +
       "so it has stopped. " +
       "UNINSTALL this app, and RE-INSTALL it. " +
       "Be careful that when you " +
       "install this app, the QPair should be " +
       "already installed on your " +
       "device", Toast.LENGTH_LONG).show();
    return false;
}

 

If the method does not return PERMISSION_GRANTED, give a guide for users to delete the application and re-install it after installing the QPair application..

 

3) When the version of the QPair application is old

Users have to use the latest version of the QPair application. We cannot accept responsibility for any malfunctions or errors when you use old version of the QPair application.

 

Determine the version of the QPair application which is installed by using the following QPair property:

QPairConstants.PROPERTY_SCHEME_AUTHORITY + “/local/qpair/version”

 

For the detailed information about QPair properties, see Monitoring Property Changes.

 

It is better to open the installation page of the QPair application (https://play.google.com/store/apps/details?id=com....) if the device has no QPair package.

 

You can use Android APIs such as PackageInfo.versionCode to retrieve the version code of the QPair application. In this case, use QPairConstants.PACKAGE_NAMEas the package name of the QPair application.

 

4) When user does not connect his or her phone and G Pad via the QPair application.

Before doing QPair-related jobs, you have to check the QPair connection.

 

Determine whether the connection is established by using the following QPair property:

QPairConstants.PROPERTY_SCHEME_AUTHORITY + "/local/qpair/is_connected

 

For the detailed information about QPair properties, see Monitoring Property Changes.

 

If the connection is not established, run the QPair application for users to make a connection.

Navigation