在 xml 文件中,我有以下代码。我可以通过单击 ringtonepref 屏幕中的广告铃声按钮来选择 mp3 声音,但是当我这样做时,我看到以下异常。这以前可以工作,但在更新到 android 8 之后它就不能工作了。
怎么可能
<RingtonePreference
android:defaultValue="content://settings/system/notification_sound"
android:key="ringtone_pref"
android:ringtoneType="all"
android:title="@string/hr_beep_tone_title"
android:summary="@string/hr_beep_tone_summary"/>
01-17 00:21:15.785 15503-16432/? E/RingtonePickerActivity: Unable to add new ringtone
java.lang.IllegalArgumentException: Unsupported ringtone type: 7
at android.media.RingtoneManager.getExternalDirectoryForType(RingtoneManager.java:1088)
at android.media.RingtoneManager.addCustomExternalRingtone(RingtoneManager.java:1056)
at com.android.providers.media.RingtonePickerActivity$2.doInBackground(RingtonePickerActivity.java:281)
at com.android.providers.media.RingtonePickerActivity$2.doInBackground(RingtonePickerActivity.java:278)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
最佳答案
翻了一下android-27的源码,好像是addCustomExternalRingtone复制了你选择的声音文件,但是给定的参数TYPE_ALL不允许确定保存目录.
添加自定义外部铃声
@WorkerThread
public Uri addCustomExternalRingtone(@NonNull final Uri fileUri, final int type)
throws FileNotFoundException, IllegalArgumentException, IOException {
...
// Choose a directory to save the ringtone. Only one type of installation at a time is
// allowed. Throws IllegalArgumentException if anything else is given.
final String subdirectory = getExternalDirectoryForType(type);
// Find a filename. Throws FileNotFoundException if none can be found.
final File outFile = Utils.getUniqueExternalFile(mContext, subdirectory,
Utils.getFileDisplayNameFromUri(mContext, fileUri), mimeType);
// Copy contents to external ringtone storage. Throws IOException if the copy fails.
try (final InputStream input = mContext.getContentResolver().openInputStream(fileUri);
final OutputStream output = new FileOutputStream(outFile)) {
Streams.copy(input, output);
}
// Tell MediaScanner about the new file. Wait for it to assign a {@link Uri}.
try (NewRingtoneScanner scanner = new NewRingtoneScanner(outFile)) {
return scanner.take();
} catch (InterruptedException e) {
throw new IOException("Audio file failed to scan as a ringtone", e);
}
}
和getExternalDirectoryForType,这里实际发生了错误。
private static final String getExternalDirectoryForType(final int type) {
switch (type) {
case TYPE_RINGTONE:
return Environment.DIRECTORY_RINGTONES;
case TYPE_NOTIFICATION:
return Environment.DIRECTORY_NOTIFICATIONS;
case TYPE_ALARM:
return Environment.DIRECTORY_ALARMS;
default:
throw new IllegalArgumentException("Unsupported ringtone type: " + type);
}
}
问题是RingtonePickerActivity不能决定选择哪种类型保存,最后给TYPE_ALL。
看来你应该覆盖选择文件的点,将uri和类型传递给RingtoneManager.addCustomExternalRingtone,或者自己保存文件。
关于android - RingtonePreference 在 android 8.1 上添加新铃声失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54231751/
当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/
我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它
我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以
我已经构建了一些serverspec代码来在多个主机上运行一组测试。问题是当任何测试失败时,测试会在当前主机停止。即使测试失败,我也希望它继续在所有主机上运行。Rakefile:namespace:specdotask:all=>hosts.map{|h|'spec:'+h.split('.')[0]}hosts.eachdo|host|begindesc"Runserverspecto#{host}"RSpec::Core::RakeTask.new(host)do|t|ENV['TARGET_HOST']=hostt.pattern="spec/cfengine3/*_spec.r
当谈到运行时自省(introspection)和动态代码生成时,我认为ruby没有任何竞争对手,可能除了一些lisp方言。前几天,我正在做一些代码练习来探索ruby的动态功能,我开始想知道如何向现有对象添加方法。以下是我能想到的3种方法:obj=Object.new#addamethoddirectlydefobj.new_method...end#addamethodindirectlywiththesingletonclassclass这只是冰山一角,因为我还没有探索instance_eval、module_eval和define_method的各种组合。是否有在线/离线资
我注意到类定义,如果我打开classMyClass,并在不覆盖的情况下添加一些东西我仍然得到了之前定义的原始方法。添加的新语句扩充了现有语句。但是对于方法定义,我仍然想要与类定义相同的行为,但是当我打开defmy_method时似乎,def中的现有语句和end被覆盖了,我需要重写一遍。那么有什么方法可以使方法定义的行为与定义相同,类似于super,但不一定是子类? 最佳答案 我想您正在寻找alias_method:classAalias_method:old_func,:funcdeffuncold_func#similartoca
我有带有Logo图像的公司模型has_attached_file:logo我用他们的Logo创建了许多公司。现在,我需要添加新样式has_attached_file:logo,:styles=>{:small=>"30x15>",:medium=>"155x85>"}我是否应该重新上传所有旧数据以重新生成新样式?我不这么认为……或者有什么rake任务可以重新生成样式吗? 最佳答案 参见Thumbnail-Generation.如果rake任务不适合你,你应该能够在控制台中使用一个片段来调用重新处理!关于相关公司
我正在尝试使用Curbgem执行以下POST以解析云curl-XPOST\-H"X-Parse-Application-Id:PARSE_APP_ID"\-H"X-Parse-REST-API-Key:PARSE_API_KEY"\-H"Content-Type:image/jpeg"\--data-binary'@myPicture.jpg'\https://api.parse.com/1/files/pic.jpg用这个:curl=Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")curl.multipart_form_
我正在尝试在Rails上安装ruby,到目前为止一切都已安装,但是当我尝试使用rakedb:create创建数据库时,我收到一个奇怪的错误:dyld:lazysymbolbindingfailed:Symbolnotfound:_mysql_get_client_infoReferencedfrom:/Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundleExpectedin:flatnamespacedyld:Symbolnotfound:_mysql_get_client_infoReferencedf
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路