无法识别ViewEventActivity.class

时间:2015-02-02 07:57:36

标签: android wear-os

我的代码来源是https://developer.android.com/training/wearables/notifications/creating.html

在这个示例代码中,第二部分NotificationCompat的工作方式就像一个charm ..但我在MainActivity.class中有这个代码,并且它给出了一个错误" ViewEventActivity.class无法识别"

现在这个ViewEventActivity.class是什么,在哪里添加它以及如何实现这个

代码段::

   int notificationId = 001;
    // Build intent for notification content
    Intent viewIntent = new Intent(this, ViewEventActivity.class);
    viewIntent.putExtra(EXTRA_EVENT_ID, eventId);
    PendingIntent viewPendingIntent =
            PendingIntent.getActivity(this, 0, viewIntent, 0);

    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_event)
            .setContentTitle(eventTitle)
            .setContentText(eventLocation)
            .setContentIntent(viewPendingIntent);

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

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

任何建议都会有很大的帮助

2 个答案:

答案 0 :(得分:4)

Repalce

Intent viewIntent = new Intent(this, ViewEventActivity.class);

Intent viewIntent = new Intent();

单击Notification时启动活动的示例代码。它与Android API无关。如果您要在点击时启动任何活动,请用Activity重新ViewEventActivity.class,否则忽略它< / p>

答案 1 :(得分:3)

  

&#34;无法识别ViewEventActivity.class&#34;

ViewEventActivity与任何API类无关。所以你需要创建自己的类,你想要在通知点击时点击任意名称,而不是像其他类一样点击ViewEventActivity

通过扩展ViewEventActivity

,在您的应用中创建Activity

同时在ViewEventActivity

中将AndroidManifest.xml类添加为活动
 <activity
     android:name=".ViewEventActivity"
      ...  
  />