从扩展文件设置通知声音

时间:2019-05-16 05:12:25

标签: android notifications android-notifications android-fileprovider apk-expansion-files

我正在设置动态通知声音,并希望从android中的扩展文件进行设置。那有可能吗?如果是,那我该如何设置或访问扩展文件(.wav)进行编码(通知生成器),请为同一共享一些代码

我的尝试:

FCM代码:

 val AUTHORITY = "com.example.provider.SampleZipFileProvider"
        val CONTENT_URI = Uri.parse("content://$AUTHORITY")

     val defaultSoundUri =    Uri.parse("$CONTENT_URI/${appNotification.sound_name}")


        val notificationBuilder = NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon)
            .setContentTitle(getString(R.string.app_name))
            .setStyle(NotificationCompat.BigTextStyle().bigText(appNotification.message))
            .setWhen(0)
            .setChannelId(Constants.NOTIFICATION_CHNANEL_ID)
            .setContentText(appNotification.message.decodeUnicode())
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent)

SampleZipFileProvider.class

public class SampleZipFileProvider extends APEZProvider {
// main content provider URI
private static final String CONTENT_PREFIX = "content://";

// must match what is declared in the Zip content provider in
// the AndroidManifest.xml file
private static final String AUTHORITY = "com.example";

public static final Uri ASSET_URI = Uri.parse(CONTENT_PREFIX + AUTHORITY);

public String getAuthority() {
    return AUTHORITY;
}

}

清单:

 <provider android:name=".zipfile.SampleZipFileProvider"
              android:authorities="com.example"
              android:exported="false"
              android:grantUriPermissions="true"
              android:multiprocess="true">
        <meta-data android:name="mainVersion"
                   android:value="1"/>

    </provider>

1 个答案:

答案 0 :(得分:0)

尝试阅读the docs on expansion files,然后问一个更具体的问题,即您不了解的内容。建议您在不确定时使用Apk Expansion Zip library