相关疑难解决方法(0)

全屏意图不启动活动,但在 android 10 上显示通知

我尝试使用下一个代码为广播接收器启动活动

 Intent i = new Intent(context, AlarmNotification.class);
 i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { // This is at least android 10...

                NotificationManager mgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

                if (mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) {
                    mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER,
                            "Whatever", NotificationManager.IMPORTANCE_HIGH));
                }

                mgr.notify(NOTIFY_ID, buildNormal(context, i).build());

            }

private NotificationCompat.Builder buildNormal(Context context, Intent intent) {

    NotificationCompat.Builder b=
            new NotificationCompat.Builder(context, CHANNEL_WHATEVER);

    b.setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_ALL)
            .setSmallIcon(android.R.drawable.ic_lock_idle_alarm)
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(TEXT)
            .setContentText(TEXT)
            .setFullScreenIntent(buildPendingIntent(context, intent), true);

    return(b);

}

private PendingIntent buildPendingIntent(Context context, Intent intent) {

    return(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
}
Run Code Online (Sandbox Code Playgroud)

一开始,一切正常。但是如果我进入应用程序设置,关闭CHANNEL_WHATEVER的通知通道,然后再打开它。稍后当我调用 NotificationManager.notify 时,它会在通知抽屉中显示通知,但不会启动活动。如果我删除该应用程序并重新安装,它又可以正常工作了。这是我应该报告的 android 10 …

android broadcastreceiver android-intent android-pendingintent android-10.0

11
推荐指数
1
解决办法
1万
查看次数

FLAG_TURN_SCREEN_ON并不总是有效

我从BroadcastReceiver启动一个活动,它由alaram(RTC_WAKEUP类型)触发.在onCreate的那个活动我添加这些标志

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
    WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
    WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
    WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON        
);
Run Code Online (Sandbox Code Playgroud)

问题是有时(大约10%的情况)屏幕无法打开.警报被正确触发(我这里是通知的声音,这也是在接收器的onReceive()中触发的.然后,如果我按下电话的电源按钮,屏幕会亮起,显示我的活动,并立即关闭.那个,电源按钮工作正常.这发生在android 2.3.7上,这里是onReceive()方法

@Override
public void onReceive(Context context, Intent intent) {
    m_Context = context;

    Bundle extras = intent.getExtras();
    final int id = extras.getInt("timer_id");

    Intent activityIntent = new Intent(m_Context, MyActivity.class);
    activityIntent.putExtra("timer_id", id);
    activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    m_Context.startActivity(activityIntent);

    // and now load the alarm sound and play it for the desired time
    showFinishedNotification();
}
Run Code Online (Sandbox Code Playgroud)

我想避免使用PowerManager,因为它需要一个权限,并且标志是首选的方式.

什么可能是一个问题?logcat没有显示任何问题......

android screen wakeup

10
推荐指数
3
解决办法
7988
查看次数

全屏通知

我想创建一个全屏通知。我使用以下代码实现了一个通知。我需要做哪些更改才能使其成为全屏通知。

    private void showNotification(String data) {

    Intent i = new Intent(this, MapsActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setAutoCancel(true)
            .setContentTitle("FCM Test")
            .setContentText(data)
            .setSmallIcon(R.drawable.common_google_signin_btn_icon_dark)
            .setContentIntent(pendingIntent);

    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    manager.notify(0,builder.build());
}
Run Code Online (Sandbox Code Playgroud)

android

8
推荐指数
2
解决办法
1万
查看次数

锁屏时如何显示来电画面?

我正在开发我的自定义呼叫应用程序,例如 Skype,当我收到 fcm 消息时,我需要向用户显示“来电”屏幕。为此,我使用全屏意图通知。我现在的代码是这样的:

        val intent = Intent(Intent.ACTION_MAIN, null)
        val fakeIntent = Intent()
        intent.flags = Intent.FLAG_ACTIVITY_NO_USER_ACTION or Intent.FLAG_ACTIVITY_NEW_TASK
        intent.setClass(ctx, IncomingCallActivity::class.java!!)
        val pendingIntent = PendingIntent.getActivity(ctx, 1, intent, 0)
        val pendingIntent2 = PendingIntent.getActivity(ctx, 1, fakeIntent, PendingIntent.FLAG_ONE_SHOT)
        val builder = Notification.Builder(ctx)
        builder.setOngoing(true)
        builder.setPriority(Notification.PRIORITY_HIGH)

        // Set notification content intent to take user to fullscreen UI if user taps on the
        // notification body.
        builder.setContentIntent(pendingIntent)
        // Set full screen intent to trigger display of the fullscreen UI when the notification
        // manager deems it appropriate. …
Run Code Online (Sandbox Code Playgroud)

android voip webrtc

8
推荐指数
1
解决办法
6350
查看次数