我正在尝试开发一个可以轻松发送短信的小部件扩展程序。这很有效,但我想确认通过振动智能手表发送了短信。我可以从小部件扩展程序启动振动器吗?
据我了解,发送主机应用程序的意图应该足以启动振动。
在我的类中扩展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
我还尝试创建扩展ControlExtension的单独Vibrator类:
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);
}
}
从小部件扩展中触发振动没有任何效果。我忽视的东西?非常感谢!
答案 0 :(得分:1)
似乎在小部件触摸上启动振动的唯一方法是启动一个sparate ControlExtension:
小工具onTouch:
Intent intent = new Intent(Control.Intents.CONTROL_START_REQUEST_INTENT);
intent.putExtra(Control.Intents.EXTRA_AEA_PACKAGE_NAME, mContext.getPackageName());
sendToHostApp(intent);
在注册信息中:
将getRquiredControlApiVersion设置为返回1.
并在ExtensionService中添加:
@Override
public ControlExtension createControlExtension(String hostAppPackageName) {
return new Vibrator(hostAppPackageName, this);
}
和振动器类:
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);
}
}
}
这份工作。