How should I do to start SmartWatch Extension from the program code?

混江龙づ霸主 提交于 2020-01-09 10:59:27

问题


I want to know the method of starting SmartWatch Extension from the program code. For instance, Intent etc. I registered the script language for SmartWatch in Google Play the other day. It divides into two programs, one is registered as SmartWatch Extension(BitmapCatcher), and another is registered as smart phone application (Luarida). The script starts from a smart phone. Here, I want to start BitmapCatcher at the same time as starting the script. The way is not understood though it is thought that BitmapCatcher can be started without the screen touch if Intnent is sent to LiveWare.

Please teach the program code in which SmartWatch Extension is started without the screen touch.

(It was recommended to ask Mr. Jerker on this site when I wrote this question in the Smart Extras discussion of a Sony mobile site.)


SmartWatch Extension was not able to be started from other Android applications though it tested referring to your explanation. Please teach again.
What should I write in "Your.package.name"?
Moreover, what should I write in "HostAppPackageName"?

The one that starts by sendBroadcast is BitmapCatcher. This package name is "com.luaridaworks.smartwatch.bitmapcatcher".
In the test program, it wrote as follows. It continues to the following comment.

package com.luaridaworks.test02;
 import com.sonyericsson.extras.liveware.aef.control.Control;
 import com.sonyericsson.extras.liveware.aef.registration.Registration;
 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
 public class Test02Activity extends Activity {
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Intent intent = new Intent(Control.Intents.CONTROL_START_REQUEST_INTENT);
        intent.putExtra(Control.Intents.EXTRA_AEA_PACKAGE_NAME, "com.luaridaworks.smartwatch.bitmapcatcher");
        intent.setPackage("com.luaridaworks.smartwatch.bitmapcatcher");
        sendBroadcast(intent, Registration.HOSTAPP_PERMISSION);
     }
 } 

Because BitmapCatcher did not start, Intent was rewritten as follows and it tested.

intent = new Intent(Control.Intents.CONTROL_START_REQUEST_INTENT);
intent.putExtra(Control.Intents.EXTRA_AEA_PACKAGE_NAME, "com.luaridaworks.smartwatch.bitmapcatcher");
intent.setPackage("com.sonyericsson.extras.liveware");
sendBroadcast(intent, Registration.HOSTAPP_PERMISSION);

It did not start similarly. Intent was rewritten as follows and tested.

intent = new Intent(Control.Intents.CONTROL_START_REQUEST_INTENT);
intent.putExtra(Control.Intents.EXTRA_AEA_PACKAGE_NAME, "com.luaridaworks.smartwatch.bitmapcatcher");
intent.setPackage("com.luaridaworks.test02");
sendBroadcast(intent, Registration.HOSTAPP_PERMISSION);

It did not start similarly. Intent was rewritten as follows and tested.

intent = new Intent(Control.Intents.CONTROL_START_REQUEST_INTENT);
intent.putExtra(Control.Intents.EXTRA_AEA_PACKAGE_NAME, "com.luaridaworks.test02");
intent.setPackage("com.luaridaworks.smartwatch.bitmapcatcher");
sendBroadcast(intent, Registration.HOSTAPP_PERMISSION);

It did not start similarly. Intent was rewritten as follows and tested.

intent = new Intent(Control.Intents.CONTROL_START_REQUEST_INTENT);
intent.putExtra(Control.Intents.EXTRA_AEA_PACKAGE_NAME, "com.sonyericsson.extras.liveware");
intent.setPackage("com.luaridaworks.smartwatch.bitmapcatcher");
sendBroadcast(intent, Registration.HOSTAPP_PERMISSION);

It did not start similarly. It has not succeeded yet.
Please give the example of the program code named com.luaridaworks.test02 in which "com.luaridaworks.smartwatch.bitmapcatcher" is usually started from the application program.


回答1:


You request to start your extension by sending the START_REQUEST intent, as defined in the SDK utility classes. There is also a reference of this in chapter 6.1 in the API specification of the SDK.

Intent intent = new Intent(Control.Intents.CONTROL_START_REQUEST_INTENT);
intent.putExtra(Control.Intents.EXTRA_AEA_PACKAGE_NAME, "your.package.name");
intent.setPackage(hostAppPackageName);
sendBroadcast(intent, Registration.HOSTAPP_PERMISSION);

The reference "your.package.name" is the package name that was stored to the extension database, when your extension was registered. If you look at the examples in the SDK, each extension example has a SampleRegistrationInformation with a method getExtensionRegistrationConfiguration. This is where the registration is stored to the database via a ContentProvider. The following line stores your package name.

values.put(Registration.ExtensionColumns.PACKAGE_NAME, mContext.getPackageName());

I think, from looking at your examples, that your package name is "com.luaridaworks.smartwatch.bitmapcatcher"?

The hostAppPackageName is the package name of the SmartWatch host application. Information about this package name is sent with every intent that you receive from the host application. In the SDK samples, we store the host app package name in a global variable to be used later, hence the reference in the code to hostAppPackageName. I talk a bit more about this in this question. If you want to hard code the host app package name, this is it: com.sonyericsson.extras.smartwatch. But I recommend you don't, since it could change in the future.

So, the following (with hard coding) should work for you:

Intent intent = new Intent(Control.Intents.CONTROL_START_REQUEST_INTENT);
intent.putExtra(Control.Intents.EXTRA_AEA_PACKAGE_NAME, "com.luaridaworks.smartwatch.bitmapcatcher");
intent.setPackage("com.sonyericsson.extras.smartwatch");
sendBroadcast(intent, Registration.HOSTAPP_PERMISSION);


来源:https://stackoverflow.com/questions/10971674/how-should-i-do-to-start-smartwatch-extension-from-the-program-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!