Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android Wearの通知メモ

Android Wearの通知メモ

自分用のメモ

Get Started with the Developer Preview | Android Developers

例のコマンド

    $adb -d forward tcp:5601 tcp:5601

sample

通知だすだけ+タップでアクティビティ移動

        int notificationId = 1;

        Intent viewIntent = new Intent(this, CallActivity.class);
        viewIntent.putExtra("key", "value");
        PendingIntent viewPendingIntent =
                PendingIntent.getActivity(this, 0, viewIntent, 0);

         NotificationCompat.Builder notificationBuilder =
                 new NotificationCompat.Builder(this)
                         .setSmallIcon(R.drawable.ic_launcher)
                         .setContentTitle("ContentTitle")
                         .setContentText("ContentText")
                         .setContentIntent(viewPendingIntent);

         NotificationManagerCompat notificationManager =
                 NotificationManagerCompat.from(this);

         notificationManager.notify(notificationId, notificationBuilder.build());

通知+地図アプリにIntent

        int notificationId = 1;
    
        Intent viewIntent = new Intent(this, CallActivity.class);
        viewIntent.putExtra("key", "value");
        PendingIntent viewPendingIntent =
                PendingIntent.getActivity(this, 0, viewIntent, 0);

        Intent mapIntent = new Intent(Intent.ACTION_VIEW);
        Uri geoUri = Uri.parse("geo:0,0?q=100,100");
        mapIntent.setData(geoUri);
        PendingIntent mapPendingIntent =
                PendingIntent.getActivity(this, 0, mapIntent, 0);

        BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
        bigStyle.bigText("Big Text");

        NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_event)
                    .setLargeIcon(BitmapFactory.decodeResource(
                            getResources(), R.drawable.ic_bigicon))
                    .setContentTitle("ContentTitle")
                    .setContentText("ContentText")
                    .setContentIntent(viewPendingIntent)
                    .addAction(R.drawable.ic_map,"Map", mapPendingIntent)
                    .setStyle(bigStyle);

        NotificationManagerCompat notificationManager =
                NotificationManagerCompat.from(this);

        notificationManager.notify(notificationId, notificationBuilder.build());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.