当我使用代码时,我的应用程序出现问题:
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
java.lang.SecurityException:Permission Denial:打开提供者 com.adobe.reader.misc.ARFileProvider
在Manifest中我尝试添加
<uses-permission android:name="com.adobe.reader.misc.ARFileProvider.READ_DATABASE"/>
<uses-permission android:name="com.adobe.reader.misc.ARFileProvider.WRITE_DATABASE"/>
<uses-permission android:name="com.adobe.reader.misc.ARFileProvider"/>
<uses-permission android:name="com.adobe.reader.misc"/>
<uses-permission android:name="com.adobe.reader.misc.READ_DATABASE"/>
<uses-permission android:name="com.adobe.reader.misc.WRITE_DATABASE"/>
<uses-permission android:name="com.adobe.reader"/>
但是当我想要来自Adobe Reader或InputStream的uri光标时,我总是有这个错误...
帮帮我吧:) 谢谢大家
拉尔夫
答案 0 :(得分:0)
<强>清单强>
<?xml version="1.0" encoding="utf-8"?>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
<uses-permission android:name="android.permission.READ_USER_DICTIONARY"/>
<uses-permission android:name="com.adobe.reader.misc.ARFileProvider.READ_DATABASE"/>
<uses-permission android:name="com.adobe.reader.misc.ARFileProvider.WRITE_DATABASE"/>
<uses-permission android:name="com.adobe.reader.misc.ARFileProvider"/>
<uses-permission android:name="com.adobe.reader.misc"/>
<uses-permission android:name="com.adobe.reader.misc.READ_DATABASE"/>
<uses-permission android:name="com.adobe.reader.misc.WRITE_DATABASE"/>
<uses-permission android:name="com.adobe.reader"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver android:name="pl.coig.intradokmobile.UserInterface.Services.ShareService$CloseButtonListener" />
<receiver android:name="pl.coig.intradokmobile.UserInterface.MainApplication.DocumentDetailsFragment$ServiceReceiver" />
<activity
android:name="pl.coig.intradokmobile.UserInterface.DiagnosticActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name" >
</activity>
<activity
android:name="pl.coig.intradokmobile.UserInterface.StartupConfigPages.FirstApplicationRunActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name" >
</activity>
<activity
android:name="pl.coig.intradokmobile.UserInterface.MainApplication.MainActivity"
android:configChanges="keyboardHidden|screenSize|orientation"
android:label="@string/app_name" >
</activity>
<activity
android:name="pl.coig.intradokmobile.UserInterface.StartupConfigPages.ChooseStartupScreenActivity"
android:configChanges="keyboardHidden|screenSize|orientation"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="pl.coig.intradokmobile.UserInterface.StartupConfigPages.ConnectToActivity"
android:configChanges="keyboardHidden|screenSize|orientation"
android:label="@string/app_name" >
</activity>
<activity
android:name="pl.coig.intradokmobile.UserInterface.StartupConfigPages.ConfigSummarySuccessActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name="pl.coig.intradokmobile.UserInterface.StartupConfigPages.ConfigSummaryFailureActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name="pl.coig.intradokmobile.UserInterface.StartupConfigPages.CaptureActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
</activity>
<activity
android:name="pl.coig.intradokmobile.UserInterface.ShareActivity"
android:theme="@style/Theme.Transparent" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="video/*" />
<data android:mimeType="audio/*" />
<data android:mimeType="text/*" />
<data android:mimeType="text/x-vcard" />
<data android:mimeType="text/plain" />
<data android:mimeType="text/html" />
<data android:mimeType="text/rtf" />
<data android:mimeType="application/zip" />
<data android:mimeType="application/vnd.ms-excel" />
<data android:mimeType="application/msword" />
<data android:mimeType="application/vnd.ms-powerpoint" />
<data android:mimeType="application/pdf" />
<data android:mimeType="application/doc" />
<data android:mimeType="application/docx" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.txt" />
<data android:pathPattern=".*\\.pdf" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
<activity
android:name="pl.coig.intradokmobile.UserInterface.EnterShop"
android:label="@string/app_name"
android:theme="@style/Theme.Transparent" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
<activity
android:name="pl.coig.intradokmobile.UserInterface.StartupConfigPages.ManualPairDeviceActivity"
android:label="@string/title_activity_manual_pair_device" >
</activity>
<activity
android:name="pl.coig.intradokmobile.UserInterface.MainApplication.SearchActivity"
android:label="@string/app_name"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<service
android:name="pl.coig.intradokmobile.UserInterface.Services.ShareService"
android:enabled="true" >
</service>
<service
android:name="pl.coig.intradokmobile.UserInterface.Services.DownloadService"
android:enabled="true" >
</service>
<activity
android:name="pl.coig.intradokmobile.UserInterface.FilePicker.BackHandlingFilePickerActivity"
android:label="@string/app_name"
android:theme="@style/FilePickerTheme" >
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service
android:name="pl.coig.intradokmobile.UserInterface.Services.DownloadAllService"
android:exported="false" >
</service>
<activity
android:name="pl.coig.intradokmobile.UserInterface.MainApplication.FeedbackActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
</activity>
<receiver
android:name="pl.coig.intradokmobile.Models.NetworkChangeReceiver"
android:label="NetworkChangeReceiver" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
</intent-filter>
</receiver>
</application>
我使用Adobe Reader内容uri的部分代码
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
InputStream inputStream = context.getContentResolver().openInputStream(uri);
来自Adobe Reader的Uri就是那样的想法
内容://com.adobe.reader.fileprovider/root_external/storage/emulated/0/Download/Adobe%2 0Acrobat / document.pdf
我从意图
获得此UriUri fileUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
<强> logcat的:强>
java.lang.SecurityException: Permission Denial: opening provider com.adobe.reader.misc.ARFileProvider from ProcessRecord{1f7f73c1 16260:pl.coig.intradokmobile/u0a133} (pid=16260, uid=10133) that is not exported from uid 10092
at android.os.Parcel.readException(Parcel.java:1546)
at android.os.Parcel.readException(Parcel.java:1499)
at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3350)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:4664)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2533)
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1442)
at android.content.ContentResolver.query(ContentResolver.java:462)
at android.content.ContentResolver.query(ContentResolver.java:422)
at pl.coig.intradokmobile.Models.FileManager.getRealPathFromURI(FileManager.java:451)
at pl.coig.intradokmobile.Models.FileManager.getFileFromUri(FileManager.java:358)
at pl.coig.intradokmobile.UserInterface.Services.ShareService.handleSendFile(ShareService.java:320)
at pl.coig.intradokmobile.UserInterface.Services.ShareService.onHandleIntent(ShareService.java:103)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
答案 1 :(得分:0)
private void showPdf(String path) {
Uri uri = getUri(path);
Intent intent =intentForOtherApps(uri);
Intent openintent = Intent.createChooser(intent, "Open File");
try{
startActivity(openintent);
}catch (ActivityNotFoundException e){
}
}
}
private Intent intentForOtherApps(Uri imageUriforPDF) {
Intent openpdfIntent = new Intent(Intent.ACTION_VIEW);
openpdfIntent.setDataAndType(imageUriforPDF, "application/pdf");
openpdfIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
openpdfIntent.addFlags(PendingIntent.FLAG_UPDATE_CURRENT);
if ( Build.VERSION.SDK_INT <= 23 ) {
List<ResolveInfo> resInfoList = getApplicationContext().getPackageManager().
queryIntentActivities(openpdfIntent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
getApplicationContext().grantUriPermission(packageName, imageUriforPDF, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
openpdfIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION );
openpdfIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
return openpdfIntent;
}
private Uri getUri(String path) {
Uri fileUri= FileProvider.getUriForFile(context,
"myprovider.fileprovider",
new File(path));
return fileUri;
}