0
我試圖從我的應用程序的緩存目錄的短信應用程序發送一個位圖文件提供。我正在使用文件提供程序向處理意圖的應用程序授予臨時權限。當我嘗試發送意圖,並從意向選擇器中選擇默認的Android短信應用時,我的消息應用崩潰,並且出現此錯誤。我試圖從選擇的意圖選擇器如電子郵件和其他信息應用其他應用程序,它似乎做工精細,僅使用默認的短信應用程序崩潰。拒絕的權限通過意圖
java.lang.SecurityException: Permission Denial: reading android.support.v4.content.FileProvider uri content://com.example.brandon.emojimms2/shared_images/image.png from pid=9804, uid=10024 requires the provider be exported, or grantUriPermission()
private void shareImage()
{
File imagePath = new File(mContext.getCacheDir(), "images");
File newFile = new File(imagePath, "image.png");
Uri contentUri = FileProvider.getUriForFile(mContext, "com.example.brandon.emojimms2", newFile);
if (contentUri != null) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // temp permission for receiving app to read this file
shareIntent.setDataAndType(contentUri, mContext.getContentResolver().getType(contentUri));
shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
startActivity(Intent.createChooser(shareIntent, "Choose an app"));
}
}
我相當肯定我設置的文件提供正確的代碼,但這裏是在情況下,它需要的清單。
編輯:我只是做了一些測試,似乎與短信應用程序的崩潰發生在早期的apis手機上,但正在開發新的apis,如7.1。文本消息應用程序或者您應該授予讀取權限更改的方式嗎?
請張貼在一個正常的方式:文字。沒有圖像,請。 – greenapps
我一直在做一些測試,似乎這個錯誤可能從使用與舊郵件系統com.android.mms導致此權限錯誤文件提供的事實是未來的,因爲運行的新郵件系統版本的Android com.android.messaging似乎工作正常。 –