Skip to content

Instantly share code, notes, and snippets.

@takahirom
Last active July 6, 2019 09:33
Show Gist options
  • Save takahirom/1ff10c15f81c4023420d to your computer and use it in GitHub Desktop.
Save takahirom/1ff10c15f81c4023420d to your computer and use it in GitHub Desktop.
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