全屏通知仅显示为抬头

时间:2015-09-03 00:19:29

标签: android android-notifications android-fullscreen

我已经把这个问题撞到了桌子上3天了,请告诉我我在哪里迷路了。

当我收到传入的VoIP电话时,我正试图显示全屏通知,就像PhoneApp那样。如果用户处于身临其境的活动中,我可以抬起头来。但是,我只收到抬头通知,并且从未获得全屏。我也需要通知忽略锁定屏幕。

这是我正在做的事情:

    String callJson = call.toJson(uber).toString();
    uber.requestWakeState(UberVoice.WAKE_STATE_FULL);

    final Notification.Builder builder = new Notification.Builder(uber);
    builder.setSmallIcon(R.drawable.switch_notification);
    if (image != null) {
        builder.setLargeIcon(image);
    }
    builder.setOngoing(true);

    PendingIntent inCallPendingIntent =
            PendingIntent.getActivity(uber, 234,
                    UberVoice.createInCallIntent(), 0);
    builder.setContentIntent(inCallPendingIntent);

    builder.setContentText(body);
    builder.setUsesChronometer(false);

    builder.setContentTitle(title);

    builder.setCategory(Notification.CATEGORY_CALL);
    builder.setVisibility(Notification.VISIBILITY_PUBLIC);

    builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE), AudioManager.STREAM_RING);
    builder.setVibrate(new long[]{500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500});

    builder.setPriority(Notification.PRIORITY_MAX);
    builder.setTicker(title);
    builder.setFullScreenIntent(inCallPendingIntent, true);

    builder.addAction(R.drawable.hangup_action, "Reject", CallService.getPendingIntent(uber, callJson, CallService.REJECT));
    builder.addAction(R.drawable.answer_action, "Answer", CallService.getPendingIntent(uber, callJson, CallService.ANSWER));

    NotificationManager notificationManager = (NotificationManager) uber.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = builder.build();
    notificationManager.notify(INCOMING_CALL_NOTIFICATION_ID, notification);

这是creatCallIntent代码:

public static Intent createInCallIntent() {
    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
            | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
            | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
    intent.setClassName("<package>", IncomingCallActivity.class.getName());
    return intent;
}

这是IncomingCallActivity.onCreate()

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int flags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
            | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;

    getWindow().addFlags(flags);

    setContentView(R.layout.activity_incoming_call);

我已尝试直接启动此活动(uber是应用程序参考)

Intent incomingCallIntent = new Intent(uber, IncomingCallActivity.class);
String callJson = call.toJson(uber).toString();
incomingCallIntent.putExtra("call", callJson);

incomingCallIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

uber.startActivity(incomingCallIntent);

我做错了什么?

2 个答案:

答案 0 :(得分:2)

想出来!就像我怀疑的那样,这是一种愚蠢的事情。

在我的IncomingCallActivity中,我有以下代码

public void onPause() {
    super.onPause();
    finish();
}

事实证明,与通知显示方式有关的内容实际上是调用onPause,因此完成了活动。

感谢@JohanShogun试图提供帮助。

答案 1 :(得分:1)

//in android 10 a permssion is used try it
 
 <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT"/>
相关问题