也许我的问题听起来像是被问了100次,但相信我,我已经读过这100个类似问题的每一个答案,没有一个解决了我的问题。因此,我的本机扩展的目的是共享我的应用缓存文件夹中的文档(doc、pdf等)。使用第三方应用程序(Quick Office、Adobe Reader等)。我发现FileProvider和Intents应该可以解决我的问题。
我的app描述文件包含:
<application android:enabled="true"
android:launchMode="singleInstance">
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.test.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application>
在Eclipse的项目属性、->、Java Build Path、-> Order和Export selected中选择: Android Private libraries和Android Dependencies。android-support-v4.jar在项目的libs文件夹中。
FREFunction代码摘录:
package com.test.OpenWithDefaultApp.functions;
.....
import android.content.Intent;
import android.net.Uri;
import android.support.v4.content.FileProvider;
.....
Uri contentUri = FileProvider.getUriForFile(context.getActivity(), "com.test.OpemWithDefaultApp.fileprovider", file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(contentUri, fileType);
.....
context.getActivity().startActivity(intent);
.....
我正在使用
Eclipse Luna 4.4.0
Eclipse Android Plugin 23.0.3
Android SDK Tools 23.0.2
Android SDK Platform-tools 20
Android SDK Build-tools 20
Android SDK from 14 upto 20
Android Support Library 20
Google Play services 19
原生扩展结构:
+android
-libs/android-support-v4.jar
-res/xml/file_paths
-library.swf
-openwithdefaultapp.jar
+default
-library.swf
-extension.xml
但是我被错误所困扰:
java.lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/air.testFileProvider-2.apk"],nativeLibraryDirectories=[/data/app-lib/air.testFileProvider-2, /vendor/lib, /system/lib]]
任何帮助都将不胜感激。谢谢
发布于 2017-09-07 18:20:52
android:authorities="com.test.fileprovider"
和"com.test.OpemWithDefaultApp.fileprovider"
,这两个名称应该相同
发布于 2021-05-10 02:07:52
在AndroidManifest.xml中
变化
<provider android:name="android.support.v4.content.FileProvider"
至
<provider android:name="androidx.core.content.FileProvider"
经过测试并为我工作
https://stackoverflow.com/questions/25291350
复制相似问题