
我用这段代码发出通知:
notificationmanager nm = (notificationmanager) getSystemService(NOTIFICATION_SERVICE);//Create your notificationint icon = R.drawable.ic_launcher;CharSequence tickerText = " message";long when = System.currentTimeMillis();Notification notification = new Notification(icon, tickerText,when);Context context = getApplicationContext();CharSequence contentTitle = last_notifs_array[0][2];CharSequence contentText = "New Message";PendingIntent pIntent = PendingIntent.getActivity(notifService.this,0, intent1,0);notification.setLatestEventInfo(context,contentTitle,contentText,pIntent);// Send the notificationnm.notify(HELLO_ID,notification);但是,当我点击通知时,我想开始一项活动.我怎样才能做到这一点?
解决方法:
试试这个:代替YourActivity,将您想要调用的所需活动清除
notificationmanager nm = (notificationmanager) getSystemService(NOTIFICATION_SERVICE); // Create your notification int icon = R.drawable.ic_launcher; CharSequence tickerText = " message"; Intent notificationIntent long when = System .currentTimeMillis(); Notification notification = new Notification( icon, tickerText, when); notificationIntent = new Intent(context, YourActivity.class); Context context = getApplicationContext(); CharSequence contentTitle = last_notifs_array[0][2]; CharSequence contentText = "New Message"; PendingIntent pIntent = PendingIntent .getActivity( notifService.this, 0, notificationIntent, 0); notification .setLatestEventInfo( context, contentTitle, contentText, pIntent); // Send the notification nm.notify(HELLO_ID, notification); 总结 以上是内存溢出为你收集整理的java – 单击通知时启动活动全部内容,希望文章能够帮你解决java – 单击通知时启动活动所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)