2011-12-21 46 views
0

如何在点击通知栏上的图像后指定活动? 我该如何制作意图? 谢谢。Android按下通知时如何进行意图活动

public class AlarmService extends BroadcastReceiver { 
NotificationManager nm; 

@Override 
public void onReceive(Context context, Intent intent) { 
    nm = (NotificationManager) context 
      .getSystemService(Context.NOTIFICATION_SERVICE); 
    CharSequence from = "Check your fridge"; 
    CharSequence message = "It's time to eat!"; 
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, 
      new Intent(), 0); 
    Notification notif = new Notification(R.drawable.fridge_icon3, 
      "Keep Fridge", System.currentTimeMillis()); 
    notif.setLatestEventInfo(context, from, message, contentIntent); 
    notif.defaults |= Notification.DEFAULT_SOUND; 
    notif.flags |= Notification.FLAG_AUTO_CANCEL; 
    nm.notify(1, notif); 
} 
} 

回答

1

您发布的代码已经有一个意图,例如,你在contentIntent中有新的Intent()。这是没有太大用处,因为你没有填写任何东西。你需要这样的东西。

Intent notificationIntent = new Intent(this, MyAvtivity.class); 
// modify the intent as nessasary here. 
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); 

用户指南here

+1

谢谢您的指导。我把这样\t \t的PendingIntent contentIntent = PendingIntent.getActivity(上下文,0, \t \t \t \t新意图(上下文,KeepFridgeActivity.class),0);不管怎样,谢谢! – wholee1 2011-12-22 09:12:52

+0

同样的问题发生在我和你的解决方案工作.. :-)干杯! – YuDroid 2012-11-10 10:07:36

相关问题