0
我正在爲Galaxy Gear編寫一個應用程序進行一些研究。 我需要「抓住」來自手機的通知,並將我自己的通知放在Gear上。如何通知銀河齒輪
那麼,重點是:我如何通知齒輪本身?
以下代碼工作有關Galaxy S4,但不扔在銀河齒輪的通知...
我創建了服務與方法「onCreated()」和「onStartCommand做下面的代碼() 「: MyNotificationSvc.java
private void doJob() throws InterruptedException{
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("My notification")
.setContentText("Hello World!");
Intent mainIntent = new Intent(this, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(mainIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(123, mBuilder.build());
stopSelf();
}
我開始 「MyNotificationSvc」 按鈕時, 「被點擊StartSvc」。 點擊後,該應用程序「最小化」,10秒後應該出現通知。 注意:不是來自智能手機!通知應該由Galaxy Gear自己提出。
爲 「StartSvc」 - 按鈕的onclick,方法是:
public void startSvc(View v){
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
startService(new Intent(this, MyNotificationSvc.class));
}
我在AppManifest.xml
<service android:name=".MyNotificationSvc"></service>
加入這一行
太謝謝你了!