相关疑难解决方法(0)

在Android O中不推荐使用NotificationCompat.Builder

将我的项目升级到Android O后

buildToolsVersion "26.0.1"
Run Code Online (Sandbox Code Playgroud)

Android Studio中的Lint显示以下通知构建器方法的已弃用警告:

new NotificationCompat.Builder(context)
Run Code Online (Sandbox Code Playgroud)

问题是: Android开发人员更新了描述NotificationChannel的文档以支持Android O中的通知,并为我们提供了一个代码段,但使用了相同的弃用警告:

Notification notification = new Notification.Builder(MainActivity.this)
        .setContentTitle("New Message")
        .setContentText("You've received new messages.")
        .setSmallIcon(R.drawable.ic_notify_status)
        .setChannelId(CHANNEL_ID)
        .build();  
Run Code Online (Sandbox Code Playgroud)

通知概述

我的问题:是否还有其他解决方案可用于构建通知,并且仍然支持Android O?

我找到的解决方案是将通道ID作为Notification.Builder构造函数中的参数传递.但是这种解决方案并不完全可以重复使用.

new Notification.Builder(MainActivity.this, "channel_id")
Run Code Online (Sandbox Code Playgroud)

notifications android android-notifications

139
推荐指数
6
解决办法
12万
查看次数

通知无法在Android Oreo中显示(API 26)

尝试在Android O上显示通知时,我收到此消息.

对于音量控制以外的操作,不推荐使用流类型

该通知直接来自示例文档,并在Android 25上显示正常.

android push-notification android-8.0-oreo android-8.1-oreo

43
推荐指数
3
解决办法
3万
查看次数

Android O中的NotificationChannel问题

在使用Android Messages ver 2.3.063发送彩信时,我正在举报"开发人员警告包com.google.android.apps.messaging".

在日志中

08-12 16:57:52.368  7661  7682 W Notification: Use of stream types is deprecated for operations other than volume control
08-12 16:57:52.368  7661  7682 W Notification: See the documentation of setSound() for what to use instead with android.media.AudioAttributes to qualify your playback use case
08-12 16:57:52.369  1604  3146 E NotificationService: No Channel found for pkg=com.google.android.apps.messaging, channelId=miscellaneous, id=5, tag=null, opPkg=com.google.android.apps.messaging, callingUid=10130, userId=0, incomingUserId=0, notificationUid=10130, notification=Notification(channel=miscellaneous pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x8 color=0xff2a56c6 vis=PRIVATE)
08-12 16:57:52.375  1604  3094 D …
Run Code Online (Sandbox Code Playgroud)

android android-notifications android-8.0-oreo

40
推荐指数
2
解决办法
3万
查看次数

无法在频道"null"上发布通知目标Api为26

两个日志显示

1:对于音量控制以外的操作,不推荐使用流类型

2:请参阅setSound()的文档,了解使用什么来代替android.media.AudioAttributes来限定播放用例

显示这个

android android-notifications android-8.0-oreo

36
推荐指数
3
解决办法
4万
查看次数

什么是通知通道ID?通知在api 27中不起作用

我将项目api目标更新为27并且所有通知都被禁用.
api 26和27中的通知有什么区别?

        Notification notif = new NotificationCompat.Builder(this)
                .setContentTitle(getString(R.string.app_name))
                .setContentText(message)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentIntent(pIntent)
                .setSound(alarmSound)
                .setAutoCancel(true).build();
        notif.ledARGB = 0xFFff0000;
        notif.flags = Notification.FLAG_SHOW_LIGHTS;
        notif.ledOnMS = 100;
        notif.ledOffMS = 100;

        NotificationManager notificationCompatManager =
                (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationCompatManager.notify(0, notif);
Run Code Online (Sandbox Code Playgroud)

api notifications android

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

fcm推送通知在一加6移动设备中不起作用

当设备处于后台,前景以及通过从托盘刷卡关闭某个应用程序时,FCM推送通知在以下设备中均能正常工作。品牌名称(android-Version)Micromax(5.1)摩托罗拉(7.1.1)诺基亚(8.1.0)三星(8.0.0)Nexus(8.1.0)小米(7.1.2)

但是在oneplus的情况下,当通过从托盘中刷卡关闭应用程序时,fcm通知不起作用,但是当应用程序处于前景和背景中时,fcm通知将正常工作。 设备版本OnePlus 8.1.0

但是,当我手动关闭应用程序的电池优化选项时,在所有情况下,fcm推送通知在Oneplus设备中均可正常工作

我的androidManifest.xml是

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.demo.Notification"
    android:installLocation="auto">

    <uses-permission android:name="android.permission.VIBRATE" />

    <application
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

        <!-- [START fcm_default_icon] -->
        <!-- Set custom default icon. This is used when no icon is set for incoming notification messages. -->
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@mipmap/ic_launcher" />
        <!-- [END fcm_default_icon] -->
        <!-- [START fcm_default_channel] -->
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_channel_id"
            android:value="@string/default_notification_channel_id"/>
        <!-- [END fcm_default_channel] -->

        <service
            android:name=".MyFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>

        <activity
            android:name="com.demo.Notification.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity> …
Run Code Online (Sandbox Code Playgroud)

android battery push-notification oneplusx

6
推荐指数
1
解决办法
804
查看次数

NotificationManager错误Android Studio

我写了一个代码,在Beacon范围内有弹出通知.

我的通知代码如下:

private void showNotification(String message){
        Log.d("Hay8","DCM8");
        Intent intent = new Intent(context, MainActivity.class);
        Log.d("Hay9","DCM9");
        PendingIntent pendingIntent = PendingIntent.getActivity(context,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
        Log.d("Hay10","DCM10");

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context,"default")
                .setSmallIcon(android.R.drawable.ic_dialog_info)
                .setContentTitle("Notification1")
                .setContentText(message)
                .setDefaults(NotificationCompat.DEFAULT_ALL)
                .setPriority(NotificationCompat.PRIORITY_HIGH)
                .setContentIntent(pendingIntent);
        Log.d("Hay11","DCM11");



        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        Log.d("Hay12","DCM12");
        notificationManager.notify(NotiID++,builder.build());
    }
Run Code Online (Sandbox Code Playgroud)

我尝试使用日志调试,我认为问题是关于NotificationManager方法.这是日志:

05-23 17:23:30.774 18668-18668/com.example.user.estimotebeacon D/Hay8: DCM8
05-23 17:23:30.774 18668-18668/com.example.user.estimotebeacon D/Hay9: DCM9
05-23 17:23:30.776 18668-18668/com.example.user.estimotebeacon D/Hay10: DCM10
05-23 17:23:30.780 18668-18668/com.example.user.estimotebeacon D/Hay11: DCM11
05-23 17:23:30.781 18668-18668/com.example.user.estimotebeacon D/Hay12: DCM12
05-23 17:23:30.788 18668-18668/com.example.user.estimotebeacon E/NotificationManager: notifyAsUser: tag=null, id=1, user=UserHandle{0}
05-23 17:23:30.798 18668-18668/com.example.user.estimotebeacon D/Hay20: DCM20
05-23 17:23:30.859 …
Run Code Online (Sandbox Code Playgroud)

java android android-studio ibeacon estimote

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