相关疑难解决方法(0)

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

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

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

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

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

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

禁用通知的振动

我正在使用通知编写应用程序.Google开发人员指南鼓励开发人员提供设置来自定义通知(禁用振动,设置通知声音......),因此如果用户设置通知,我会尝试禁用通知振动.

NotificationCompat.Builder用来创建通知,如下所示:

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(Application.getContext())
            .setDefaults(Notification.DEFAULT_ALL)
            .setPriority(Notification.PRIORITY_MAX)
            .setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(largeIconBitmap)
            .setAutoCancel(true)
            .setContentIntent(resultPendingIntent)
            .setContentTitle(title)
            .setContentText(content);
Run Code Online (Sandbox Code Playgroud)

我尝试了不同的方法来禁用通知:

notificationBuilder.setVibrate(null);

notificationBuilder.setVibrate(new long[]{0l, 0l});

notificationBuilder.setDefaults(Notification.DEFAULT_ALL | ~Notification.DEFAULT_VIBRATE);

notificationBuilder.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND);`
Run Code Online (Sandbox Code Playgroud)

我还尝试在结果对象上构建通知并更改值:

Notification notification = notificationBuilder.build();
notification.vibrate = null;
Run Code Online (Sandbox Code Playgroud)

但是当通知出现时,手机仍会振动.

如何禁用通知振动?

notifications android vibration android-vibration

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

如何在没有声音的情况下显示通知

如何在构建时发出不发出声音的通知?我正在建立一个通知,我的用户不喜欢它发出声音的事实.

如何将其更改为静音/无声?

我如何显示通知:

android.support.v7.app.NotificationCompat.Builder builder = new android.support.v7.app.NotificationCompat.Builder(main);
builder.setStyle(new android.support.v7.app.NotificationCompat.BigTextStyle().bigText(text));
builder.setSmallIcon(R.drawable.app);
builder.setContentTitle("Rooster Maandag:");
builder.setOngoing(false);
builder.setAutoCancel(true);
builder.setDefaults(Notification.DEFAULT_ALL);
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
builder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
notificationManager = (NotificationManager) main.getSystemService(main.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, builder.build());
Run Code Online (Sandbox Code Playgroud)

我试图在谷歌搜索,但我得到的唯一结果是如何播放声音,而不是如何播放声音...

编辑 它可能在某些人的眼中是重复的,但在我的中我找不到指定默认值的替代方法,而这个新方法称为setDefaults

java notifications android ringtone android-notifications

19
推荐指数
9
解决办法
2万
查看次数

Android:通知声音禁用

我收到了这段代码的通知:

Notification notifica = new Notification();
notifica.flags |= Notification.FLAG_AUTO_CANCEL;
notifica.icon = R.drawable.serie_notification;
notifica.when = System.currentTimeMillis();
Run Code Online (Sandbox Code Playgroud)

with notifica.defaults = notifica.defaults | Notification.DEFAULT_SOUND; 我启用默认声音,但如果我想禁用声音,我该怎么办?

notifications android

15
推荐指数
5
解决办法
2万
查看次数

在Android O上禁用通知声音

我尝试在下面的方法中摆脱通知声音.

我能够将它减少到只有一次,但它应该在Android O和更低版本中完全无声.

我在stackoverflow和google上搜索了很长时间,但直到现在还没有完全奏效.

任何帮助表示赞赏.

public void showUpdateProgressNotification(int id, String appName, int progress, String status, long downloadStart) {

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        String NOTIFICATION_CHANNEL_ID = "my_channel_id_01";

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel notificationChannel = new NotificationChannel
                    (NOTIFICATION_CHANNEL_ID, "Test Notifications", NotificationManager.IMPORTANCE_LOW);
            notificationChannel.setSound(null, null);

            // Configure the notification channel.
            notificationChannel.setDescription("Channel test");
            notificationManager.createNotificationChannel(notificationChannel);
        }

        Intent cancelIntent = new Intent(ACTION_FILE_CANCEL);
        cancelIntent.putExtra("id", id);
        PendingIntent cancel = PendingIntent.getBroadcast(this, ACTION_FILE_CANCEL.hashCode() + id,
                cancelIntent, PendingIntent.FLAG_CANCEL_CURRENT);

        NotificationCompat.Builder notification = new …
Run Code Online (Sandbox Code Playgroud)

notifications android android-8.0-oreo

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

Android 8.1 W/Notification:不推荐使用流类型

只要我的服务正常工作,我就会在状态栏中保留FLAG_ONGOING_EVENT通知,并且每秒更新一次.

在Android 8之后,我添加了Notification Channel,并且8和8+设备都运行良好,但是8个以上的设备每秒都在向我的logcat填充以下警告,这非常烦人:

04-10 20:36:34.040 13838-13838/xxx.xxxx.xxxx W/Notification: Use of stream types is deprecated for operations other than volume control
See the documentation of setSound() for what to use instead with android.media.AudioAttributes to qualify your playback use case
Run Code Online (Sandbox Code Playgroud)

我很确定我没有声音通道或通知本身.

以下是我创建通知渠道的方法:

channel = new NotificationChannel(CHANNEL_ONGOING_ID,
                getString(R.string.channel_ongoing_name),
                NotificationManager.IMPORTANCE_LOW);
channel.setDescription(getString(R.string.channel_ongoing_desc));
mNotificationManager.createNotificationChannel(channel);
Run Code Online (Sandbox Code Playgroud)

我的通知:

RemoteViews view = new RemoteViews(getPackageName(),
    R.layout.notification_ongoing);

view.setImageViewResource(R.id.notification_button,
        mState == STATE_ONGOING ? R.drawable.ic_pause : R.drawable.ic_start);
view.setTextViewText(R.id.notification_text, Utils.getReadableTime(mMilliseconds));

view.setOnClickPendingIntent(R.id.notification_button,
    PendingIntent.getBroadcast(mContext, 1, new Intent(INTENT_NOTIFICATION_TOGGLE),
        PendingIntent.FLAG_UPDATE_CURRENT));

NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext,
        CHANNEL_ONGOING_ID); …
Run Code Online (Sandbox Code Playgroud)

java notifications android

9
推荐指数
1
解决办法
2851
查看次数

带有静默通知的前台服务

语境:

我一直在使用 Google 的LocationUpdatesForegroundService示例项目来了解有关服务的更多信息。

我已经通过 Github 桌面下载了该项目并在我的手机上运行它,一切都很棒,并且该项目完成了它想要做的事情。

我的手机是 Android 8.0.0,API 26

问题:

一旦应用程序终止,前台服务通知就会显示在状态栏上,一旦发生这种情况,我就会听到通知声音(默认声音)。但是,我希望通知是静音的,就像在一些基于位置的应用程序中一样(例如:Life360

到目前为止我尝试过的:

以上都不适合我,如果有人能对这种情况有所了解,我将不胜感激。

java notifications android foreground-service

5
推荐指数
1
解决办法
3503
查看次数

Android禁用通知声音

我想创建一个没有声音的通知。我怎样才能做到这一点?我尝试了以下代码,但不适用于我:

notification = mBuilder
        .setStyle(notiStyle)
        .setSmallIcon(notificationIcon)
        .setTicker(title)
        .setWhen(0)
        .setAutoCancel(true)
        .setContentTitle(title)
        .setContentIntent(resultPendingIntent)
        .setSound(null).build();
Run Code Online (Sandbox Code Playgroud)

notifications android

4
推荐指数
1
解决办法
7570
查看次数