问题描述
当我接到电话时,我正在开发一个呼叫应用程序(基于 VoIP) 我显示一个通知弹出窗口来接听或拒绝一个电话,但该弹出通知在 3-5 秒内不可见,我也想显示全屏设备锁定时的通知。我已经完成了一些代码,但没有奏效。设备锁定时我无法接听电话。
1] 通知渠道
notificationmanager = (notificationmanager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
/* Create or update. */
NotificationChannel channel = new NotificationChannel(CHANNEL_ID,aContext.getResources().getString(R.string.app_name),notificationmanager.IMPORTANCE_HIGH);//IMPORTANCE_DEFAULT);
notificationmanager.createNotificationChannel(channel);
}
createNotificationChannel();
if (!isInit) {
cancelAll();
cancelCalls();
isInit = true;
}
2] 来电通知
@SuppressLint("WrongConstant")
public void showNotificationForIncomingCall(SipCallSession callInfo) {
@SuppressWarnings("deprecation")
int icon = android.R.drawable.stat_sys_phone_call;
CharSequence tickerText = context.getText(R.string.ongoing_call);
long when = System.currentTimeMillis();
Intent callNotifIntent;
tickerText = context.getText(R.string.incoming_call);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (inComingCallNotification == null) {
inComingCallNotification = new Builder(context);
inComingCallNotification.setSmallIcon(icon);
inComingCallNotification.setTicker(tickerText);
inComingCallNotification.setPriority(NotificationCompat.PRIORITY_HIGH);
inComingCallNotification.setCategory(NotificationCompat.CATEGORY_CALL);
inComingCallNotification.setWhen(when);
inComingCallNotification.setChannelId(IN_CHANNEL_ID);
inComingCallNotification.setongoing(true);
}
} else {
if (inComingCallNotification == null) {
inComingCallNotification = new Builder(context);
inComingCallNotification.setSmallIcon(icon);
inComingCallNotification.setTicker(tickerText);
inComingCallNotification.setWhen(when);
inComingCallNotification.setongoing(true);
}
}
RemoteViews notificationLayoutHeadsUp =
new RemoteViews(
context.getPackageName(),R.layout.incoming_call_notification_heads_up);
// notificationLayoutHeadsUp.setTextViewText(R.id.caller,getString(R.string.app_name));
notificationLayoutHeadsUp.setTextViewText(R.id.sip_uri,formatRemoteContactString(callInfo.getRemoteContact(),callInfo));
Log.d("Notification: ","showNotification: called: ");
Intent hangupIntent = new Intent(context,NotificationbroadcastReceiver.class);
String INTENT_CANCEL_CALL_FORWARDING_ACTION = "com.android.cancel_call";
hangupIntent.setAction(INTENT_CANCEL_CALL_FORWARDING_ACTION);
Intent startIntent = new Intent(context,NotificationbroadcastReceiver.class);
String INTENT_START_CALL_FORWARDING_ACTION = "com.android.start_call";
startIntent.setAction(INTENT_START_CALL_FORWARDING_ACTION);
PendingIntent hangupPendingIntent =
PendingIntent.getbroadcast(context,131,hangupIntent,PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent startPendingIntent =
PendingIntent.getbroadcast(
context,startIntent,PendingIntent.FLAG_UPDATE_CURRENT);
notificationLayoutHeadsUp.setonClickPendingIntent(R.id.accept_btn,startPendingIntent);
notificationLayoutHeadsUp.setonClickPendingIntent(R.id.reject_btn,hangupPendingIntent);
prefManager.setBackgroundCall(true);
Intent notificationIntent = SipServiceNew.buildCallUiIntent(context,callInfo);
PendingIntent contentIntent = PendingIntent.getActivity(context,notificationIntent,0);
inComingCallNotification.setContentText(formatRemoteContactString(callInfo.getRemoteContact(),callInfo));
inComingCallNotification.setContentIntent(contentIntent);
inComingCallNotification.setongoing(true)
.setFullScreenIntent(contentIntent,true)
// .setCustomHeadsUpContentView(notificationLayoutHeadsUp)
.addAction(R.drawable.cancel_forwarding_bg,"Decline",hangupPendingIntent)
.addAction(R.drawable.start_forwarding_bg,"Accept",startPendingIntent)
.setVisibility(Notification.VISIBILITY_PUBLIC);
Notification notification = inComingCallNotification.build();
notification.flags |= Notification.FLAG_NO_CLEAR;
notificationmanager.notify(131,notification);
}
3] 清单权限
<uses-permission android:name="android.permission.WAKE_LOCK" />
android:showOnLockScreen="true"
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)