我想我已经从他们的网站上学会了如何在android studio中创建nootification,并对它的运行方式有了简单的了解。我可以进行更多的复制和粘贴,只需稍作修改即可。但我没有看到任何关于如何使用intent在同一个活动/类中启动方法的内容。
根据我的复制和粘贴代码从安卓工作室:
public void showNotification()
{
Intent emptyIntent = new Intent(this, JellyNotify.class);
TaskStackBuilder backStack = TaskStackBuilder.create(this)
.addNextIntent(emptyIntent)
.addParentStack(JellyNotify.class);
PendingIntent emptyPending = backStack.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT);
Notification buildNoti = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.jelly)
.setContentTitle("Feeling Jelly")
.setContentText("Tap to launch Jar of Jelly")
.setContentIntent(emptyPending)
.build();
NotificationManager manageNotification = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
manageNotification.notify(0,buildNoti);
}
我想我想说的是,当用户点击正在进行的通知时,我正在尝试启动和活动或新的意图,我甚至可以是我创建的类或新活动中的一个方法。所以在过去的一周里,我的大脑为搜索而感到兴奋。为了展示我的想法,我发现了以下网站:
android-er.blogspot
可点击通知-StackOverflow
试试这个,
更新您的意向如下,
public void showNotification()
{
NotificationManager manageNotification = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
Notification buildNoti = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.jelly)
.setContentTitle("Feeling Jelly")
.setContentText("Tap to launch Jar of Jelly")
.setContentIntent(emptyPending)
.build();
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,new Intent(this, Activity_you_needto_launch.class), PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
manageNotification.notify(0,buildNoti);
}