问题
I have been banging my head against the table with this problem for 3 days now, please tell me where I have strayed.
When I am getting an incoming VoIP call, I am trying to show a full screen notification, just like the PhoneApp does. I am ok with heads up, if the user is in an immersive activity. However, I am getting only a heads up notification, and never getting a full screen. I need to notification to ignore the lock screen as well.
Here is what I am doing:
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);
Here is the creatCallIntent code:
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;
}
And here is the 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);
I have tried starting this activity directly(uber is Application reference)
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);
What am I doing wrong?
回答1:
If I understood your question correctly, you forgot to add flag WindowManager.LayoutParams.FLAG_FULLSCREEN
in IncomingCallActivity
@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
| WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().addFlags(flags);
This combination needed to show activity while screen is locked. Hope it helps.
回答2:
Figured it out! It was something stupid just as I suspected.
In my IncomingCallActivity I had the following bit of code
public void onPause() {
super.onPause();
finish();
}
It turns out that something having to do with how Notifications get shown actually calls onPause
, therefore finishing the activity.
Thanks to @JohanShogun for attempting to help out.
来源:https://stackoverflow.com/questions/32365177/full-screen-notification-only-showing-as-a-heads-up