【问题标题】:Set Notification Sound from expansion file从扩展文件设置通知声音
【发布时间】:2019-05-16 05:12:25
【问题描述】:

我正在设置动态通知声音,并想从 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>

【问题讨论】:

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


【解决方案1】:

尝试阅读the docs on expansion files,然后针对您不了解的内容提出更具体的问题。如果您不确定,建议使用Apk Expansion Zip library

【讨论】:

  • 我已经使用 zip 库在媒体播放器及其作品中播放媒体,但我不知道使用 URI 将扩展声音文件用作通知声音
  • 这更有帮助。现在唯一缺少的是解释什么不起作用。它无法构建吗?它会崩溃吗?它运行了,但没有播放通知?日志中有什么?您可能会发现 stackoverflow.com/help/how-to-ask 很有帮助
  • 是的,运行成功,没有崩溃,但没有声音
猜你喜欢
  • 2012-02-06
  • 2011-07-05
  • 1970-01-01
  • 2012-07-03
  • 1970-01-01
  • 1970-01-01
  • 2011-03-03
  • 2019-06-29
  • 1970-01-01
相关资源
最近更新 更多