Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Android Wearは通知にActivityを出せる!!!
<activity
android:name=".SampleActivity"
android:exported="true"
android:allowEmbedded="true"
android:label="@string/app_name"
android:taskAffinity="" />
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wear_explain);
Intent displayIntent = new Intent(this, SampleActivity.class);
displayIntent.putExtra("title",
"sample");
PendingIntent displayPendingIntent = PendingIntent.getActivity(this,
0, displayIntent, 0);
Notification notif = buildBasicNotification(this)
.extend(new Notification.WearableExtender().setCustomSizePreset(Notification.WearableExtender.SIZE_LARGE)
.setDisplayIntent(displayPendingIntent))
.build();
NotificationManagerCompat.from(this).notify(0, notif);
}
private static Notification.Builder buildBasicNotification(Context context) {
return new Notification.Builder(context)
.setContentTitle("titleです")
.setContentText("textです")
// Set a content intent to return to this sample
.setContentIntent(PendingIntent.getActivity(context, 0,
new Intent(context, MainActivity.class), 0))
.setSmallIcon(R.drawable.ic_launcher);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment