作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我已经为这个问题头撞 table 3天了,请告诉我我在哪里迷路了。
当我接到 VoIP 来电时,我会尝试显示全屏通知,就像 PhoneApp 一样。如果用户处于身临其境的 Activity 中,我可以抬头。但是,我只收到一个提醒通知,而从未获得全屏。我也需要通知忽略锁定屏幕。
这是我正在做的事情:
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);
这里是 createInCallIntent 代码:
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);
我已尝试直接启动此 Activity (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);
我做错了什么?
最佳答案
如果我正确理解了您的问题,您忘记在 IncomingCallActivity
WindowManager.LayoutParams.FLAG_FULLSCREEN
@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);
此组合需要在屏幕锁定时显示 Activity 。希望对您有所帮助。
关于android - 全屏通知仅显示为抬头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32365177/
所以我有这个界面 public interface EventHandler { public void handleEvent(E event); } 我想为它派生处理事件的类,如下所示
我是一名优秀的程序员,十分优秀!