Notification.setSound()无法与proguard配合使用

时间:2019-02-18 07:14:30

标签: android notifications proguard

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

app / 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();

1 个答案:

答案 0 :(得分:1)

也许将proguard配置为保留与通知相关的类和音频类?这是部分示例:

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