如何向Android wear emulator发送通知

如何向Android wear emulator发送通知,android,wear-os,Android,Wear Os,我遵循古尔格关于如何实施的指南 我是在一个模拟器上开发的,但是这个该死的东西不会接收来自另一个模拟器甚至物理设备的通知。。我需要一些指导 这是我的密码 Intent viewIntent = new Intent(getApplicationContext(), Not.class); // viewIntent.putExtra(EXTRA_EVENT_ID, eventId); PendingIn

我遵循古尔格关于如何实施的指南

我是在一个模拟器上开发的,但是这个该死的东西不会接收来自另一个模拟器甚至物理设备的通知。。我需要一些指导

这是我的密码

    Intent viewIntent = new Intent(getApplicationContext(),
                    Not.class);
            // viewIntent.putExtra(EXTRA_EVENT_ID, eventId);
            PendingIntent viewPendingIntent = PendingIntent.getActivity(
                    getApplicationContext(), 0, viewIntent, 0);

            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
                    getApplicationContext())
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle("Done").setContentText("In my face")
                    .setContentIntent(viewPendingIntent);

            // Get an instance of the NotificationManager service
            NotificationManagerCompat notificationManager = NotificationManagerCompat
                    .from(getApplicationContext());

            // Build the notification and issues it with notification
            // manager.
            notificationManager.notify(1,
                    notificationBuilder.build());

创建无磨损的移动应用程序

然后插入此代码

然后在手持仿真器上运行应用程序。并查看磨损模拟器上的通知。(可能需要向下滑动才能找到它)

public class MyActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);


    Intent intent = new Intent(this, MyActivity2.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(MyActivity.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Action action = new NotificationCompat.Action.Builder(
            R.drawable.ic_launcher,
            getString(R.string.wearTitle),
            pendingIntent).build();

    Notification notification = new NotificationCompat.Builder(MyActivity.this)
            .setContentText("title")
            .setContentText("content")
            .setSmallIcon(R.drawable.ic_launcher)
            .extend(new NotificationCompat.WearableExtender().addAction(action))
            .build();

    NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
    notificationManagerCompat.notify(001, notification);

}
}