我是的developing SOS application,当我收到每个通知时,android app我想打开一个alert pop-up会显示发件人的一些详细信息SOS icons并continuous alert tone会响起的铃声,我正在使用下面的代码来完成,但是在android 9上活动不会开始。而start activity当app为时,此代码不会显示killed。
private void sendNotification(String messageBody, String notificationType, String notificationId) {
try {
Intent intent = new Intent(this, SosPopUpActivity.class);
intent.putExtra("message", messageBody);
intent.putExtra("notification_type", notificationType);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel mChannel = new NotificationChannel(
channelId, channelName, importance);
notificationManager.createNotificationChannel(mChannel);
}
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
// NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_notification)
.setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_launcher))
.setContentTitle(getString(R.string.app_name))
.setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
.setContentText(messageBody)
.setAutoCancel(false)
.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getApplicationContext().getPackageName() + "/" + R.raw.sos))
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
notificationBuilder.setSmallIcon(R.drawable.ic_notification);
notificationBuilder.setColor(getResources().getColor(R.color.colorPrimary));
//notificationBuilder.setColor(getResources().getColor(R.color.notification_color));
} else {
notificationBuilder.setSmallIcon(R.drawable.ic_notification);
}
notificationBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
// NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// notificationManager.notify(1234, notificationBuilder.build());
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addNextIntent(intent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
notificationBuilder.setContentIntent(resultPendingIntent);
notificationManager.notify(1234, notificationBuilder.build());
//startActivity(intent);
}catch (Exception e)
{
e.printStackTrace();
AlertDialogHelper.showAlertDialog(this,e.getLocalizedMessage());
}
}
*Please help* .
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。