[英]Start activity or full screen intent from background in android
I have to start call activity from background when someone calls.当有人打电话时,我必须从后台开始通话活动。 I have tried this code but it's not working.我已经尝试过这段代码,但它不起作用。 Notification is not come and no error exists.通知未到来且不存在错误。 What mistake I had made.我犯了什么错误。
Intent fullScreenIntent = new Intent(conn, IncCallActivity.class);
fullScreenIntent.putExtra("name", callerName);
fullScreenIntent.putExtra("out", false);
fullScreenIntent.putExtra("channel_id", channelId);
fullScreenIntent.putExtra("id", callerId);
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(conn, 112,fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Uri sound = Uri.parse(((AppBack) getApplication()).shared().getString("ringU", "no"));
NotificationManager notificationManager =(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel mChannel = notificationManager.getNotificationChannel("VIDEO_CALL");
AudioAttributes attributes = new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_ALARM)
.build();
if (mChannel == null) {
mChannel = new NotificationChannel("VIDEO_CALL", "VIDEO_CALL",NotificationManager.IMPORTANCE_HIGH);
mChannel.setSound(sound, attributes);
notificationManager.createNotificationChannel(mChannel);
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(conn, " VIDEO_CALL").setSmallIcon(R.drawable.logo)
.setContentTitle("Incoming call")
.setContentText("Call from " + callFrom)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_CALL)
.setContentIntent(fullScreenPendingIntent)
.setFullScreenIntent(fullScreenPendingIntent, true)
.setAutoCancel(true)
.setOngoing(true);
Notification notification = builder.build();
notificationManager.notify(120, notification);
I think you should add permission to AndroidManifest.xml
.我认为您应该向AndroidManifest.xml
添加权限。
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.