Notification.setSound()不适用于proguard

问题描述 投票:0回答:1

我有proguard问题,包括通知库。如果启用了proguard,我听不到通知声音。我找不到哪个库是个问题。

应用程序/的build.gradle:

实现'com.google.android.gms:play-services-auth:16.0.1'

实现'com.google.android.gms:play-services-gcm:16.0.0'

实施'com.google.firebase:firebase-core:16.0.7'

实施'com.google.firebase:firebase-messaging:17.3.4'

实施'com.crashlytics.sdk.android:crashlytics:2.9.8'

实现'com.android.support:appcompat-v7:28.0.0'

实现'com.android.support:support-v13:28.0.0'

实现'com.android.support:design:28.0.0'

实现'com.android.support:recyclerview-v7:28.0.0'

实现'com.android.support:cardview-v7:28.0.0'

我的节目:

# google gms
-dontwarn com.google.android.gms.**
-keep class com.google.android.gms.** { *; }
-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents(); }
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL; }

-keep class com.google.android.gms.internal.** { *; }
-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR; }

# fabric https://docs.fabric.io/android/crashlytics/dex-and-proguard.html
-keepattributes Signature
-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**
-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception

# android support
-keepnames class !android.support.v7.internal.view.menu.**, ** { *; }
-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class * extends android.support.v4.view.ActionProvider {
    public <init>(android.content.Context); }
-keep public class * extends android.support.design.widget.CoordinatorLayout.Behavior { *; }
-keep public class * extends android.support.design.widget.ViewOffsetBehavior { *; }

代码:

    Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification);
    AudioAttributes attributes = new AudioAttributes.Builder()
                    .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                   .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
                    .build();

    // over android 8.0
    NotificationChannel mChannel = new NotificationChannel(Constants.MISSED_CALL, getString(R.string.notification), NotificationManager.IMPORTANCE_HIGH);

    mChannel.setSound(uri, attributes);
    getNotificationManager().createNotificationChannel(mChannel);

    // < 8.0
    android.app.Notification notification = builder
                    .setCategory(NotificationCompat.CATEGORY_CALL)
                    .setSound(uri)
                    .setStyle(setNotificationList(notificationList))
                    .build();
android notifications proguard
1个回答
1
投票

也许配置proguard来保持通知相关的类和音频类?这是一个部分示例:

https://github.com/pusher/push-notifications-android/blob/master/pushnotifications/proguard-rules.pro

© www.soinside.com 2019 - 2024. All rights reserved.