我在使用时只在我的应用程序中的华为设备上发生异常FileProvider.getUriForFile:
Exception: java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/<card name>/Android/data/<app package>/files/.export/2016-10-06 13-22-33.pdf
at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(SourceFile:711)
at android.support.v4.content.FileProvider.getUriForFile(SourceFile:400)
Run Code Online (Sandbox Code Playgroud)
以下是我的清单中文件提供程序的定义:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>
Run Code Online (Sandbox Code Playgroud)
具有已配置路径的资源文件:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path name="external_files" path="" />
</paths>
Run Code Online (Sandbox Code Playgroud)
关于这个问题的原因以及它为什么只在华为设备上发生的任何想法?鉴于我没有华为设备,我该怎么调试呢?
更新:
我已经添加了更多的登录到我的应用程序,我得到了一些打印时都不一致的结果ContextCompat.getExternalFilesDirs,并context.getExternalFilesDir在这些设备:
ContextCompat.getExternalFilesDirs:
/storage/emulated/0/Android/data/<package>/files
/storage/sdcard1/Android/data/<package>/files
context.getExternalFilesDir:
/storage/sdcard1/Android/data/<package>/files
Run Code Online (Sandbox Code Playgroud)
这与该ContextCompat.getExternalFilesDirs州的文件不一致The first path returned is the same as getExternalFilesDir(String)
这解释了我context.getExternalFilesDir在我的代码和FileProvider使用中使用的问题ContextCompat.getExternalFilesDirs.
我正在构建一个Android应用程序,我使用Action Bar Icon Pack中的图标在操作栏中使用.我通过文件menu夹中的xml文件定义它们.有没有办法"着色"这些图标,使它们都是相同的颜色?到目前为止,我必须使用图像编辑软件手动完成,但如果我决定改变颜色,我必须重新做一遍.
我知道有一个android:tint属性,ImageView但我还没有找到一种方法将它用于菜单的图标.
谢谢
我要迁移ViewPager到,ViewPager2因为后者应该可以解决前者的所有问题。不幸的是,当与结合使用时FragmentStateAdapter,我找不到任何方法来获取当前显示的片段。
viewPager.getCurrentItem()给出当前显示的索引,adapter.getItem(index)通常Fragment为当前索引创建一个新索引。除非保留对中所有创建的片段的引用,否则getItem()我不知道如何访问当前显示的片段。
使用old时ViewPager,一种解决方案是调用adapter.instantiateItem(index),它将以所需的索引返回该片段。
我错过了什么ViewPager2吗?
我正在使用类型意图ACTION_CREATE_DOCUMENT将文件从我的应用程序保存到设备上。有没有一种方法可以同时创建多个文档来实现此目的?我正在考虑使用EXTRA_ALLOW_MULTIPLE,但我不知道如何提供我想要创建的文档数量。
感谢您的帮助。
我的崩溃报告工具报告一个频繁的错误,主要是在Android 5.0.2的小米设备上:
Fatal Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CREATE_DOCUMENT cat=[android.intent.category.OPENABLE] typ=application/pdf (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1765)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1602)
at android.app.Activity.startActivityFromFragment(Activity.java:4391)
at android.app.Fragment.startActivityForResult(Fragment.java:1100)
at android.app.Fragment.startActivityForResult(Fragment.java:1084)
这些设备不支持 SAF 有什么原因吗?我怎样才能以适当的方式解决这个问题?
我在我现有的应用程序中开始使用RxAndroid.我从一个非常简单的活动开始,我有一个搜索字段,当文本发生变化时,我会使用Retrofit联系API.我还想在开始新请求之前取消当前未完成的请求.这是我到目前为止:
private Subscription currentRequestSubscription = null;
// Create stream of filtered queries
Observable<String> queryObservable = RxTextView.textChanges(searchView)
.startWith("")
.debounce(DELAY_BEFORE_REQUEST, TimeUnit.MILLISECONDS)
.map(new Func1<CharSequence, String>() {
@Override
public String call(CharSequence charSequence) {
return charSequence.toString();
}
})
// Make search request and update UI
queryObservable.observeOn(Schedulers.io())
.subscribe(new Action1<String>() {
@Override
public void call(String query) {
if (currentRequestSubscription != null) {
currentRequestSubscription.unsubscribe();
}
currentRequestSubscription = createAPIRequestObservable(query)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(... update UI with results ...);
}
});
Run Code Online (Sandbox Code Playgroud)
我觉得存储订阅并不是真正的响应式编程.我怎么能以更标准的方式做到这一点?