Last active
July 6, 2019 09:33
-
-
Save takahirom/1ff10c15f81c4023420d to your computer and use it in GitHub Desktop.
Android Wearは通知にActivityを出せる!!!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<activity | |
android:name=".SampleActivity" | |
android:exported="true" | |
android:allowEmbedded="true" | |
android:label="@string/app_name" | |
android:taskAffinity="" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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