相关疑难解决方法(0)

如何在android中获取uri的图像资源

我需要打开一个意图来查看图像,如下所示:

Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("@drawable/sample_1.jpg");
intent.setData(uri);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

问题是这Uri uri = Uri.parse("@drawable/sample_1.jpg");是不正确的.

android uri

92
推荐指数
5
解决办法
8万
查看次数

使用引用资源 ID 的声音 URI 时,Android 通知通道声音停止工作

我们为在 Oreo 及更高版本上运行的设备创建了通知渠道,这些渠道使用位于我们/res/raw文件夹中的自定义通知声音。最近,当用户升级我们的应用程序时,通知声音停止工作,通知只会振动设备。

我们已确认卸载/重新安装或清除应用程序数据可解决此问题。但是,为了在无需重新安装的情况下再次为所有人提供通知声音,我们需要从本质上删除并重新创建这些频道。

我们创建通知通道如下:

fun initNotificationChannel(channel: PSSNotificationChannel) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            val id = channel.id
            val name = context.getString(channel.nameResId)
            val importance = channel.importance
            val channel = NotificationChannel(id, name, importance)

            ...

            // Default sound
            val soundUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
                    context.applicationContext.packageName + "/" + R.raw.notification)
            val audioAttributes = AudioAttributes.Builder()
                    .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                    .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                    .build()
            channel.setSound(soundUri, audioAttributes)

            val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager?
            notificationManager?.createNotificationChannel(channel)
        }
    }
Run Code Online (Sandbox Code Playgroud)

我已经验证该文件仍然存在于/res/raw. 似乎导致此问题的提交只是文件/res夹中添加/修改的一些文件。

android android-notifications android-8.0-oreo android-9.0-pie

3
推荐指数
1
解决办法
866
查看次数