Ho sbattuto la testa contro il tavolo con questo problema per 3 giorni, per favore dimmi dove mi sono allontanato.Notifica a schermo intero che mostra solo come Heads Up
Quando ricevo una chiamata VoIP in arrivo, sto tentando di mostrare una notifica a schermo intero, proprio come fa PhoneApp. Sto bene a testa alta, se l'utente è in un'attività immersiva. Tuttavia, ricevo solo una notifica di avviso e non riesco a ottenere uno schermo intero. Ho bisogno di notifica per ignorare anche la schermata di blocco.
Ecco quello che sto facendo:
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);
ecco il codice 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;
}
ed ecco l'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);
ho provato iniziare direttamente questa attività (è necessario il riferimento Application)
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);
Cosa sto sbagliando?
[Notification.fullScreenIntent:] (https://developer.android.com/reference/android/app/Notification.html#fullScreenIntent) L'interfaccia utente del sistema può scegliere di visualizzare una notifica di risposta all'avviso anziché lanciare questa intenzione , mentre l'utente sta utilizzando il dispositivo. – adneal
Sì no. Lo capisco, ma ovviamente il mio telefono "sceglie" per mostrare a schermo intero per telefono, perché non per la mia app? La mia app del telefono mostra correttamente l'heads-up se sono impegnato in un'attività immersiva. – Leo
@Leo Se una notifica con ID 'INCOMING_CALL_NOTIFICATION_ID' è già attiva,' fullScreenIntent' per la nuova notifica verrà ignorata. Potrebbe essere questo il problema con cui hai a che fare? – Vikram