Reputation: 21
I'm trying to develop a little widget extension that sends a sms on tap. This works quite well but I would like to get a confirmation that the sms has been sent by vibrating the smartwatch. Can i start the vibrator from widget extension?
As I understand sending a intent to host app should be enough to start vibration.
In my class extending WidgetExtension onTouch:
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("124124512", null, "blaa", null, null); // Works fine
Intent intent = new Intent(Control.Intents.CONTROL_VIBRATE_INTENT);
intent.putExtra(Control.Intents.EXTRA_ON_DURATION, 1000);
intent.putExtra(Control.Intents.EXTRA_OFF_DURATION, 1000);
intent.putExtra(Control.Intents.EXTRA_REPEATS, 1);
intent.putExtra(Control.Intents.EXTRA_AEA_PACKAGE_NAME, mContext.getPackageName());
intent.setPackage(mHostAppPackageName);
context.sendBroadcast(intent, Registration.HOSTAPP_PERMISSION); // No vibration
I have also tried creating separate Vibrator class extending ControlExtension:
public class Vibrator extends ControlExtension{
public Vibrator(Context context, String hostAppPackageName) {
super(context, hostAppPackageName);
// TODO Auto-generated constructor stub
}
public void vibrate(){
startVibrator(1000, 1000, 1);
}
}
And firing vibrate from widget extension with no effect. Something i'm overlooking? Thanks a bunch!
Upvotes: 0
Views: 1061
Reputation: 21
Seems that the only way to start a vibration on widget touch is to start a sparate ControlExtension:
Widget onTouch:
Intent intent = new Intent(Control.Intents.CONTROL_START_REQUEST_INTENT);
intent.putExtra(Control.Intents.EXTRA_AEA_PACKAGE_NAME, mContext.getPackageName());
sendToHostApp(intent);
In RegistrationInformation:
Set getRquiredControlApiVersion to return 1.
and in ExtensionService add:
@Override
public ControlExtension createControlExtension(String hostAppPackageName) {
return new Vibrator(hostAppPackageName, this);
}
and the Vibrator class:
public class Vibrator extends ControlExtension{
Vibrator(String hostAppPackageName, Context context){
super(context, hostAppPackageName);
}
@Override
public void onStart() {
vibrate();
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("123456789", null, "BLAAA", null, null);
showBitmap(new SmartWatchSampleWidgetImage(mContext, 2).getBitmap());
}
@Override
public void onTouch(final ControlTouchEvent event) {
int action = event.getAction();
if (action == Control.Intents.TOUCH_ACTION_PRESS) {
}
}
public void vibrate(){
if(hasVibrator()){
startVibrator(1000, 500, 3);
}
}
}
Does the job.
Upvotes: 1