Tips

PERMISSION MANAGEMENT

Permissions at run time

One of the major changes in Android 6.0 (API Level 23) is permission management. Previously (Android 5.1 and lower) permissions are granted at install time by declaring permissions in the manifest file. Beginning in Android 6.0, users can grant permissions at run time and choose to grant or revoke permissions individually.


To request a permission,

1) Check whether the application has the permission.

Call ContextCompat.checkSelfPermission() method to determine whether the permission has been granted or not. The method returns PERMISSION_GRANTED if granted or PERMISSION_DENIED otherwise.


2) Request the permission if necessary.

Call requestPermissions() to request the permission if the permission has not been granted (PERMISSION_DENIED returned from step 1).


3) Handle the request result callback.

The onRequestPermissionsResult() callback is invoked when the user responds to the permission dialog box. Override this callback and perform appropriate actions according to the result passed to the callback.


Consider presenting the user with an explanation message before calling requestPermissions(). By calling this method, the Android System presents a permission dialog box to the user and does not allow this dialog to be modified. Thus the explanation has to be presented beforehand.


In other case, the user might keep revoking permission request that has to be granted in order to use necessary functionality. Then showing an explanation would be a reasonable approach to help the user understand why such permission is required.

USING DUAL NETWORK

Users can access the Internet while smartphone is connected with Friends Camera device, depending on the configuration of network settings.

Using the Internet in Over-AP Connection

Suppose the smartphone and the camera device are connected to an Access Point in Over-AP connection. The smartphone can access the Internet through the Access Point (on condition that the AP provides Internet access).

Using the Internet in Soft-AP Connection

Suppose the smartphone and the camera device are connected with each other directly in Soft-AP connection. The smartphone has joined the local Wi-Fi network of the camera device. Thus the smartphone cannot access the Internet through the local Wi-Fi network of the camera device.

 

In this situation, the smartphone can use its mobile data to access the Internet.

1) Enable mobile data on the smartphone

2) Turn on ‘Switch to mobile data’ in the Wi-Fi settings

 

By turning on the ‘Switch to mobile data’ option, the smartphone switches automatically to mobile data when the Internet is unavailable through the connected Wi-Fi channel.

 

If ‘Switch to mobile data’ is turned off and the user attempts to access the Internet, the user should be notified that the user cannot access the Internet due to ‘Switch to mobile data’ turned off.

Separating Processes to Use Dual Network

Suppose your application needs to communicate with Friends Camera (e.g. capturing live stream) as well as some Internet server (e.g. Youtube server login). You have to prepare separate processes so that one process is used for communication with the camera in Wi-Fi and another process for Internet access in mobile data.

 

Note that resources such as SharedPreferences cannot be used across processes since the Contexts have been separated, either. (Android Developer Sites Note: SharedPreferences class does not support use across multiple processes.)

 

The process communicating with the camera device is bound to the Wi-Fi network by the bindProcessToNetwork() method. Therefore, you have to set up another process to use Internet (relying on the automatic switching to mobile data feature of smartphone).

 

Register the processes you want to separate in the AndroidManifest.xml file. See the following code example for how to register a Provider and an Activity in seprate processes:

 


    
        
        
        
        
        
        
    



 

The automatic switching to mobile data feature is supported on Android since Lollipop update. Some Android phones do not support ‘Switch to mobile data’ option. In this case, the separated process needs to be manually bound to mobile data network. See the following implementation example for how to bind the process to mobile data network:

 

// Connect
mConnMgr = (ConnectivityManager)mPhone.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
try {
    NetworkRequest mNetworkRequest = null;
    mNetworkCallback = new ConnectivityManager.NetworkCallback() {
        @Override
        public void onAvailable(Network network) {
            setProcessDefaultNetworkForHostResolution(network);
            bindProcessToNetowrk(network);
        }
    };
    mNetworkRequest = new NetworkRequest.Builder()
        .addTransportType(NetworkCapabilities.NET_CAPABILITY_INTERNET)
        .build();
    mConnMgr.requestNetwork(mNetworkRequest, mNetworkCallback);
} catch (Exception e) {
    log.e("Exception of startMobileDataConnection - e:" + e);
}
// Disconnect
mConnMgr.unregisterNetworkCallback(mNetworkCallback);

SWITCHING CONNECTION MODE

Friends Camera provides connectivity features, namely Soft-AP connection and Over-AP connection. Users can switch from one connection mode to another.

From Soft-AP to Over-AP

Android

1) Call connect() method of ConnectionManager class to connect to an Access Point. Set SSID and password of the target Access Point and set the mode to OVER-AP to the parameters.


OctopusManager.get(mContext).connect(ssid_string, ssid_passwd_string, ConnectionManager.OVER_AP);


2) Register a Listeners.OverAP callback to receive connection result notifications.


OctopusManager.get(mContext).registerListener(mConnectionCallback);


See Over-AP Connection (Android) for full details.


iOS

1) Call connectOverAPWithssid:password: method of FriendsLink framework to connect to an Access Point. Set SSID and password of the target Access Point.


2) Manually connect to the Access Point from the Wi-Fi Settings menu of the smartphone.


3) Call searchOverAP method of FriendsLink framework to check whether the Over-AP connection is established.


4) Check the connection results notified to the callbackConnectionOverAP: callback.


See Over-AP Connection (iOS) for full details.

From Over-AP to Soft-AP

Android

1) Call enableFriendWifiAP() method of ConnectionManager class to enable Wi-Fi Soft-AP mode of the Friends Camera device. Set the BLE address of the Friends Camera device to the paramter.


OctopusManager.getInstance(mContext).getConnectionManager().enableFriendWifiAP(prevBtAddr);


2) Register a Listeners.SoftAP callback to receive the result of the method call.


3) From onResponse() of Listeners.SoftAP, the FRIEND_AP_ENABLED code is notified if the Soft-AP mode of the Friends Camera device gets enabled.


4) Call connect() method of ConnectionManager class to connect to the Friends Camera device. Set SSID and password of the Friends Camera device and set the mode to SOFT-AP to the parameters.


@Override
public void onResponse(Listeners.Type type, int code) {
    if (type == Listeners.Type.state) {
        if (code == ConnectionManager.Result.FRIEND_AP_ENABLED) {
            OctopusManager.getInstance(mContext).getConnectionManager().connect(
prevSsid, prevPw, ConnectionManager.SOFT_AP);
        }
    }
}


iOS

1) Call enableFriendWifiAP: method of FriendsLink framework to enable Wi-Fi Soft-AP mode of the Friends Camera device. Set the CBPeripheral information of the Friends Camera device to the parameter.


2) Check the Soft-AP ON request result notified to the callbackEnableWifi callback.


3) Manually connect to the Wi-Fi network of the Friends Camera deivce from the Wi-Fi Settings menu of the smartphone.

Navigation