簡體   English   中英

從 android 的后台啟動活動或全屏意圖

[英]Start activity or full screen intent from background in android

當有人打電話時,我必須從后台開始通話活動。 我已經嘗試過這段代碼,但它不起作用。 通知未到來且不存在錯誤。 我犯了什么錯誤。

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); 

我認為您應該向AndroidManifest.xml添加權限。

<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
  1. 設備應該被鎖定

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM