2013-01-19 49 views
0

我正在嘗試開發一個小部件擴展,可以輕鬆發送短信。這工作得很好,但我想確認短信是通過振動智能手錶發送的。我可以從小部件擴展中啓動振動器嗎?索尼Smartwatch - 振動小部件水龍頭上的振動智能手錶

據我所知,發送主機應用程序的意圖應該足以啓動振動。

在延長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:

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

} 

和燒成從小窗口擴展,不影響振動。我忽略的東西?謝謝一堆!

回答

1

似乎只有這樣,才能開始小部件觸摸振動是啓動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); 

在RegistrationInformation:

設置getRquiredControlApiVersion返回1。

and in ExtensionService add:

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

做這項工作。