Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
233 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...