0

I was playing lately with my Samsung Gear 2 (not S2) smartwatch and I have created a new watch-face for it. I would like to show a weather information on it and I have found that for that task I need to use Samsung Accessory Protocol (SAP).

I followed the Samsung tutorial to create a demo app to learn how to use SAP.

I had a problem with deploying Tizen app to my watch but I found out that the lowest currently (2017) available API is 2.3.1 where Gear 2 Smartwatch has 2.2. After changing in the config.xml the

<tizen:application id="XQKp7NYwyM.SimpleSAPConsumer" package="XQKp7NYwyM" required_version="2.3.1"/>

to

<tizen:application id="XQKp7NYwyM.SimpleSAPConsumer" package="XQKp7NYwyM" required_version="2.2"/>

my application was deployed.

I created a certificate to build a signed wgt package.

I also created an android provider application according to the tutorial. Added new certificate and created a signed apk.

I copied the apk to the Samsung Galaxy S3 phone and tried to install it. Installation ended without any problem. However, after some seconds or when I try to initialize the communication from the watch I get the "Unknown sources" information from Gear Manager and my app is being deleted.

I already checked "Allow unknown sources" in the android, Gear Manager and allowed USB debugging on the smartwatch (because this is my first question here I am not allowed to post more than 2 links, so I had to give one link with all screenshots there, sorry).

Why my application is being deleted and what should I do to have it working correctly.

Tizen App - Consumer

Build using Tizen Studio 1.1.0.

config.xml

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:tizen="http://tizen.org/ns/widgets" id="http://yourdomain/SimpleSAPConsumer" version="1.0.0" viewmodes="maximized">
    <tizen:application id="XQKp7NYwyM.SimpleSAPConsumer" package="XQKp7NYwyM" required_version="2.2"/>
    <content src="index.html"/>
    <feature name="http://tizen.org/feature/screen.size.all"/>
    <icon src="icon.png"/>
    <tizen:metadata key="AccessoryServiceLocation" value="res/xml/accessoryservices.xml"/>
    <name>SimpleSAPConsumer</name>
    <tizen:privilege name="http://developer.samsung.com/privilege/accessoryprotocol"/>
    <tizen:profile name="wearable"/>
</widget>

accessoryservices.xml

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <application name="HelloAccessoryConsumers">
    <serviceProfile role="consumer" name="sapsample" version="1.0" id="/sample/hello">
    <supportedTransports>
        <transport type="TRANSPORT_BT"/>
        <transport type="TRANSPORT_WIFI"/>
    </supportedTransports>
    <serviceChannel id="123" reliability="enable" priority="low" dataRate="low"> </serviceChannel>
    </serviceProfile>
    </application>
</resources>

I can provide rest of the Tizen code (main.js, index.html) if it is needed. Right now I do not think that this has any value to the problem I am facing.

Android App - Provider

Build using Android Studio 2.2.3 Structure:

app
->assets
-->SimpleSapConsumer.wgt
->libs
-->accessory-v2.5.0.jar
-->sdk-1.0.0.jar
->src
-->main
--->java
---->com.sap.baks.sapapp.service
----->SapServiceProvider.java
--->res
---->xml
----->sapservice.xml
---->AndroidManifest.xml

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sap.baks.sapapp">

    <uses-sdk
        android:minSdkVersion="18"
        android:targetSdkVersion="25" />

    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <uses-permission android:name="com.samsung.accessory.permission.ACCESSORY_FRAMEWORK"/>
    <uses-permission android:name="com.samsung.wmanager.APP"/>
    <uses-permission android:name="com.samsung.wmanager.ENABLE_NOTIFICATION"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <service android:name=".service.SAPServiceProvider">
        </service>

        <receiver android:name="com.samsung.android.sdk.accessory.RegisterUponInstallReceiver" >
            <intent-filter>
                <action android:name="com.samsung.accessory.action.REGISTER_AGENT" />
            </intent-filter>
        </receiver>
        <receiver android:name="com.samsung.android.sdk.accessory.ServiceConnectionIndicationBroadcastReceiver" >
            <intent-filter>
                <action android:name="com.samsung.accessory.action.SERVICE_CONNECTION_REQUESTED" />
            </intent-filter>
        </receiver>

        <meta-data
            android:name="AccessoryServicesLocation"
            android:value="/res/xml/sapservices.xml" />
        <meta-data
            android:name="GearAppType"
            android:value="wgt" />
    </application>
</manifest>

sapservice.xml

<resources>
    <application name="SAPapp">
        <serviceProfile
            id="/system/sapsample"
            name="sapsample"
            role="provider"
            serviceImpl="com.sap.baks.sapapp.service.SAPServiceProvider"
            version="1.0"
            serviceLimit="ANY"
            serviceTimeout="10">
            <supportedTransports>
                <transport type="TRANSPORT_BT"/>
                <transport type="TRANSPORT_WIFI" />
            </supportedTransports>
            <serviceChannel
                id="123"
                dataRate="low"
                priority="low"
                reliability="enable"/>
        </serviceProfile>
    </application>
 </resources>

sapserviceprovider.java

I put it together with screenshots because it is quite long.

******** EDIT **********

After trying to install sample applications as @Iqbal advised I had the following results:

Tizen

I was not able to install application on my watch until I changed the API to 2.2. If the API was greater I have seen the following error:

[Initializing the launch environment...]
RDS: On
Target information: SM-R380
Application information: Id(VbsgE6bms2.HelloAccessoryConsumer), Package Name(VbsgE6bms2), Project Name(HelloAccessoryConsumer)

[Transferring the package...]
    Transferred the package: wgt stream -> /opt/usr/apps/tmp/HelloAccessoryConsumer.wgt

[Installing the package...]
path is /opt/usr/apps/tmp/HelloAccessoryConsumer.wgt
start process (install)
....
error : 61

end process (fail)
processing result : FATAL_ERROR [61] failed
spend time for pkgcmd is [1537]ms
cmd_ret:61
    An exception occurred
(Installing the package... > Fail)
An exception occurred
Unexpected stop progress...
(8.239 sec)

Summary: I have installed the application with API 2.2 and no other changes done.

Android

Using the sample application without changing anything I was able to run it and connect with the smartwatch! Yupi :) !

But I needed to know why the code I used for the first time was wrong, even if I've got it from Samsung tutorial and website.

I have found that the application is being uninstalled only if I have these lines in AndroidManifest.xml

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="com.samsung.accessory.permission.ACCESSORY_FRAMEWORK"/>
<uses-permission android:name="com.samsung.wmanager.APP"/>
<uses-permission android:name="com.samsung.wmanager.ENABLE_NOTIFICATION"/>

If I replaced the lines above with the lines below

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="com.samsung.accessory.permission.ACCESSORY_FRAMEWORK" />
<uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY" />
<uses-permission android:name="com.samsung.WATCH_APP_TYPE.Companion" />
<uses-permission android:name="com.samsung.wmanager.ENABLE_NOTIFICATION" />

everything was OK.

Can someone explain me why it is so?

******** EDIT 2 **********

For those who will search for the answer to the question from previous edit. I have found it here

Long story short:

 <uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY" />

is the line that has to present - otherwise the app will be deleted from an android device. I have not found this in any documentation to be honest.

Moreover,

<uses-permission android:name="com.samsung.WATCH_APP_TYPE.Companion" />

defines that the smartwatch application will be installed separetly from an android application. After changing Companion to Integrated one tells that a smartwatch application is intergrated and will be installed with an android provider app.

Baks
  • 3
  • 2
  • Why are you changing required_version to 2.2? – Iqbal hossain Feb 20 '17 at 07:24
  • Because when I was using the default one (2.3.1) I always got "cannot deploy" error. I can check it again today evening because I have updated my certificate. Nevertheless, do you think that this can cause the problem for android applicatin being removed? – Baks Feb 20 '17 at 11:17
  • 2.2 may not be supported SAP – Iqbal hossain Feb 20 '17 at 11:32
  • I think it does because I can run the app on my smartwatch and it tries to find a provider. Problem is that on the android side the provider app is being removed after installation. – Baks Feb 20 '17 at 12:20
  • May be for this one – Iqbal hossain Feb 21 '17 at 14:34

1 Answers1

0

Follow

Iqbal hossain
  • 1,778
  • 3
  • 17
  • 24
  • This is exactly what I did. Tizen web application cannot be install on my Samsung Gear 2 watch if the API version is not changed to 2.2. After that change I can build and deploy the app. I can run it on my watch and I get no security error. It tries to connect but does not find provider application on the android phone. When I try to install example for android provider I have the error described above. Shortly: On smartwatch works, on android does not :) – Baks Feb 20 '17 at 12:19
  • i will try them again today evening and will report me tomorrow with the results. – Baks Feb 20 '17 at 13:02