Android 通知 onClick Activity 打开失败
Android Notification onClick Activity open failed
我正在开发可以发送假短信和接收假短信的应用程序。如果我可以使用内置的短信通知更好,但我不知道方式。因此,我使用下面的代码生成通知,当我单击该通知时,什么也没有发生。请问谁能解决我的问题?单击该通知时,我需要打开消息收件箱。如有任何帮助,我们将不胜感激!
Uri sms_uri = Uri.parse("smsto:+92xxxxxxxx");
Intent sms_intent = new Intent(Intent.ACTION_SENDTO, sms_uri);
sms_intent.putExtra("sms_body", "Good Morning ! how r U ?");
PendingIntent contentIntent = PendingIntent.getService(context, 0, sms_intent, 0);
Resources res = context.getResources();
Notification noti = new Notification.Builder(context)
.setContentTitle(res.getString(R.string.app_name))
//.setContentText(res.getString(R.string.cancelText))
.setSmallIcon(android.R.drawable.ic_dialog_email)
.setTicker(res.getString(R.string.app_name))
// .setAutoCancel(true)
.setWhen(System.currentTimeMillis())
.setContentIntent(contentIntent)
.build();
NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(NOTIFICATION_SERVICE);
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);
使用
PendingIntent.getActivity(context, 0 , sms_intent, 0);
可能会有帮助!!!
我正在开发可以发送假短信和接收假短信的应用程序。如果我可以使用内置的短信通知更好,但我不知道方式。因此,我使用下面的代码生成通知,当我单击该通知时,什么也没有发生。请问谁能解决我的问题?单击该通知时,我需要打开消息收件箱。如有任何帮助,我们将不胜感激!
Uri sms_uri = Uri.parse("smsto:+92xxxxxxxx");
Intent sms_intent = new Intent(Intent.ACTION_SENDTO, sms_uri);
sms_intent.putExtra("sms_body", "Good Morning ! how r U ?");
PendingIntent contentIntent = PendingIntent.getService(context, 0, sms_intent, 0);
Resources res = context.getResources();
Notification noti = new Notification.Builder(context)
.setContentTitle(res.getString(R.string.app_name))
//.setContentText(res.getString(R.string.cancelText))
.setSmallIcon(android.R.drawable.ic_dialog_email)
.setTicker(res.getString(R.string.app_name))
// .setAutoCancel(true)
.setWhen(System.currentTimeMillis())
.setContentIntent(contentIntent)
.build();
NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(NOTIFICATION_SERVICE);
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);
使用
PendingIntent.getActivity(context, 0 , sms_intent, 0);
可能会有帮助!!!