如何解决有没有办法为 Android 10 上的特定联系人分配自定义铃声?
问题说明了一切,我有一个函数可以将电话号码传递给该函数,并且该函数会将预下载的铃声分配给具有传递电话号码的联系人(如果存在此类联系人)。问题是它只适用于 Android 9 及更低版本,当我在 Android 10 上运行它时,它什么也不做,没有异常,没有崩溃,什么都没有..
如果有人知道怎么回事,这里是函数:
private fun setCustomringtone(targetContactPhone: String): String {
val lookupUri = Uri.withAppendedpath(PhoneLookup.CONTENT_FILTER_URI,targetContactPhone)
val projection = arrayOf<String>(Contacts._ID,Contacts.LOOKUP_KEY)
val data = contentResolver.query(lookupUri,projection,null,null)!!
data.movetoFirst()
try {
// Get the contact lookup Uri
val contactID: Long = data.getLong(0)
val lookupKey = data.getString(1);
val contactUri = Contacts.getLookupUri(contactID,lookupKey)
if (contactUri == null){
Log.i(TAG_LABEL,"contactUri je null,invalid arguments?")
return "fail";
}
Log.i(TAG_LABEL,"contact uri: " + contactUri.toString()) // valid and expected Uri
// Get the path of the ringtone you'd like to use
val storage = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).path
Log.i(TAG_LABEL,"out: $storage")
val file = File(storage,"ringtone.mp3")
Log.i(TAG_LABEL,file.exists().toString()) // reasures me that the file exists
val value = Uri.fromFile(file).toString()
Log.i(TAG_LABEL,"size: " + file.length().toString() + " name: " + file.name)
val values = ContentValues()
values.put(Contacts.CUSTOM_ringtone,value)
// TRIED A COMBINATION OF THESE,They DON'T WORK
// values.put(MediaStore.MediaColumns.TITLE,file.nameWithoutExtension);
// values.put(MediaStore.MediaColumns.MIME_TYPE,"audio/mpeg");
// values.put(MediaStore.MediaColumns.SIZE,file.length())
// values.put(MediaStore.Audio.Media.IS_ringtone,true)
// values.put(MediaStore.Audio.Media.IS_NOTIFICATION,false);
// values.put(MediaStore.Audio.Media.IS_ALARM,false);
// values.put(MediaStore.Audio.Media.IS_MUSIC,false);
// values.put(MediaStore.Audio.Media.ARTIST,"example")
val res = contentResolver.update(contactUri,values,null)
Log.i(TAG_LABEL,"content resolver res: " + res.toString())
}finally {
data.close();
}
return "succes"
}
再一次,它在 Android 9 及更低版本上运行良好。此外,我似乎无法在官方文档中找到任何提及通讯录服务或类似更改的信息。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。