我在三星 S5 上连接了三星 Gear Fit R350。我开发了一个创建通知的应用程序。现在我希望通知也出现在装备上。
这是我的代码,它不起作用:
generateNotification(Context context, String message) {
int icon = R.drawable.ic_launcher;
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setLights(Color.RED, 1000, 300)
//.setVibrate(new long[]{off, on, off, on,})
.setVibrate(new long[]{0, 500, 50, 500, 250, 500,500,750})
.setContentTitle("Einbruch")
.setContentText(message)
.setSmallIcon(icon)
.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.sherwood_forest));
Intent resultIntent = new Intent(context, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
NotificationCompat.Action action =
new NotificationCompat.Action.Builder(R.drawable.ic_launcher,"Alarm",resultPendingIntent)
.build();
builder.setContentIntent(resultPendingIntent);
builder.extend(new WearableExtender().addAction(action));
NotificationManagerCompat nm = NotificationManagerCompat.from (context);
nm.notify(0, builder.build());
}