繁体   English   中英

FCM 通知在前台崩溃 MIUI - Android

[英]FCM Notification Crashes MIUI on Foreground - Android

我用我的应用程序测试推送通知。 当应用程序在前台、后台运行或被终止时,有 contentIntent 来处理通知哪个活动

在我的 HTC Desire 816 上

  1. 单击通知以在应用程序被杀死时启动活动(工作正常)

  2. 当应用程序在前台运行时单击通知以启动活动(工作正常)

  3. 当应用程序在后台运行时单击通知以启动活动(工作正常)

但是当我在小米 Note 4(MIUI 10)上测试时

  1. 单击通知以在应用程序被杀死时启动活动(工作正常)

  2. 当应用程序在前台运行时单击通知以启动活动(崩溃 - 应用程序已停止)

  3. 当应用程序在后台运行时单击通知以启动活动(崩溃 - 应用程序已停止)

日志猫:

java.lang.OutOfMemoryError: Failed to allocate a 100000012 byte allocation with 16777216 free bytes and 82MB until OOM
        at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
        at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
        at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:624)
        at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:457)
        at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1152)
        at android.content.res.ResourcesImpl.createFromResourceStream(ResourcesImpl.java:1296)
        at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:743)
        at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:585)
        at android.content.res.MiuiResourcesImpl.loadDrawable(MiuiResourcesImpl.java:317)
        at android.content.res.Resources.loadDrawable(Resources.java:872)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:930)
        at android.widget.ImageView.<init>(ImageView.java:157)
        at android.widget.ImageView.<init>(ImageView.java:145)
        at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:72)
        at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
        at androidx.appcompat.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:187)
        at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:107)
        at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1407)
        at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1457)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:752)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:883)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1019)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:879)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1019)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:879)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:522)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:430)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at com.app.MainActivity.onCreate(MainActivity.java:62)
which is -> ( setContentView(R.layout.activity_main); )
        at android.app.Activity.performCreate(Activity.java:6845)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2700)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2808)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1541)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:165)
        at android.app.ActivityThread.main(ActivityThread.java:6375)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)

尝试更改标志、添加请求 ID 和我的东西,但没有运气

        super.onMessageReceived(remoteMessage);
            showNotification(remoteMessage.getNotification().getTitle(),remoteMessage.getNotification().getBody());
    }

   private void showNotification(String title, String body){
        NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        String NOTIFICATION_CHANNEL_ID = "com.hyatna_eg.hyatna";
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_ONE_SHOT);
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
        {
            NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "Notification", NotificationManager.IMPORTANCE_DEFAULT);
            notificationChannel.setDescription("Hyatna Channel");
            notificationChannel.enableLights(true);
            notificationChannel.setLightColor(Color.BLUE);
            notificationChannel.setVibrationPattern(new long[]{0,1000,500,1000});
            notificationManager.createNotificationChannel(notificationChannel);

        }
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,NOTIFICATION_CHANNEL_ID);
        notificationBuilder.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL).setWhen(System.currentTimeMillis())
                .setSmallIcon(R.drawable.ic_notification)
                .setContentTitle(title)
                .setContentText(body)
                .setDefaults(Notification.DEFAULT_ALL)
                .setPriority(NotificationManager.IMPORTANCE_HIGH)
                .setPriority(Notification.PRIORITY_MAX)
                .setPriority(NotificationCompat.PRIORITY_MAX)
                .setSound(uri)
                .setContentIntent(pendingIntent)
                .setContentInfo("Info");

        notificationManager.notify(new Random().nextInt(),notificationBuilder.build());


    }

预计它可以像 HTC 一样正常工作,但我不知道为什么让我崩溃?

您必须加载非常高分辨率的图像,这会导致MainActivity中出现OutOfMemoryError异常。

预计它可以像 HTC 一样正常工作,但我不知道为什么让我崩溃?

它在 HTC 上工作,因为它的 PPI 密度是 267,而小米是 401。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM