I want to access my systems ringtones in flutter(我想访问我的系统铃声在颤动)
本文介绍了我想访问我的系统铃声在颤动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法使用Ffltter获取手机的所有铃声,并将选择的铃声设置为我的应用的默认铃声?
提前谢谢
推荐答案
我设法使用本机代码完成了
首先,您将在颤动端创建这些东西。
// here where your ringtones will be stored List<Object?> result = ['Andromeda']; // this is the channel that links flutter with native code static const channel = MethodChannel('com.example.pomo_app/mychannel'); // this method waits for results from the native code Future<void> getRingtones() async { try { result = await channel.invokeMethod('getAllRingtones'); } on PlatformException catch (ex) { print('Exception: $ex.message'); } }
知道您需要实现本机代码。转到MainActivity.kt
// add the name of the channel that we made in flutter code private val channel = "com.example.pomo_app/mychannel" // add this method to handle the calls from flutter MethodChannel(flutterEngine.dartExecutor.binaryMessenger, channel) .setMethodCallHandler { call, result -> when (call.method) { "getAllRingtones" -> { result.success(getAllRingtones(this)) } // this function will return all the ringtones names as a list private fun getAllRingtones(context: Context): List<String> { val manager = RingtoneManager(context) manager.setType(RingtoneManager.TYPE_RINGTONE) val cursor: Cursor = manager.cursor val list: MutableList<String> = mutableListOf() while (cursor.moveToNext()) { val notificationTitle: String = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX) list.add(notificationTitle) } return list }
就是这样,我希望这对你有帮助。有任何问题请告诉我。
这篇关于我想访问我的系统铃声在颤动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:我想访问我的系统铃声在颤动


基础教程推荐
猜你喜欢
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01