Android 7.0調(diào)用相機(jī)崩潰詳解及解決辦法
更新時間:2016年12月15日 16:52:11 作者:曉果博客
這篇文章主要介紹了 Android 7.0調(diào)用相機(jī)崩潰詳解及解決辦法的相關(guān)資料,需要的朋友可以參考下
Android 7.0調(diào)用相機(jī)崩潰解決辦法
錯誤提示:
android.os.FileUriExposedException: file:///storage/emulated/0/DCIM/IMG_1041503431.jpg exposed beyond app through ClipData.Item.getUri()
處理方式
/** * Open camera */ private void showCameraAction() { if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { requestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, getString(R.string.mis_permission_rationale_write_storage), REQUEST_STORAGE_WRITE_ACCESS_PERMISSION); } else { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getActivity().getPackageManager()) != null) { try { mTmpFile = FileUtils.createTmpFile(getActivity()); } catch (IOException e) { e.printStackTrace(); } if (mTmpFile != null && mTmpFile.exists()) { /*獲取當(dāng)前系統(tǒng)的android版本號*/ int currentapiVersion = android.os.Build.VERSION.SDK_INT; Log.e("currentapiVersion","currentapiVersion====>"+currentapiVersion); if (currentapiVersion<24){ intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTmpFile)); startActivityForResult(intent, REQUEST_CAMERA); }else { ContentValues contentValues = new ContentValues(1); contentValues.put(MediaStore.Images.Media.DATA, mTmpFile.getAbsolutePath()); Uri uri = getContext().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,contentValues); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); startActivityForResult(intent, REQUEST_CAMERA); } } else { Toast.makeText(getActivity(), R.string.mis_error_image_not_exist, Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getActivity(), R.string.mis_msg_no_camera, Toast.LENGTH_SHORT).show(); } } }
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
Android 網(wǎng)絡(luò)請求框架解析之okhttp與okio
HTTP是現(xiàn)代應(yīng)用常用的一種交換數(shù)據(jù)和媒體的網(wǎng)絡(luò)方式,高效地使用HTTP能讓資源加載更快,節(jié)省帶寬,OkHttp是一個高效的HTTP客戶端,下面這篇文章主要給大家介紹了關(guān)于OkHttp如何用于安卓網(wǎng)絡(luò)請求,需要的朋友可以參考下2021-10-10Android React Native原生模塊與JS模塊通信的方法總結(jié)
這篇文章主要介紹了Android React Native原生模塊與JS模塊通信的方法總結(jié)的相關(guān)資料,需要的朋友可以參考下2017-02-02Android消息推送:手把手教你集成小米推送(附demo)
本篇文章主要介紹了Android消息推送:手把手教你集成小米推送,非常具有實用價值,需要的朋友可以參考下。2016-12-12Android ViewPager相冊橫向移動的實現(xiàn)方法
本篇文章小編為大家介紹,Android ViewPager相冊橫向移動的實現(xiàn)方法。需要的朋友參考下2013-04-04Android使用getIdentifier()獲取資源Id的方法
這篇文章主要介紹了Android使用getIdentifier()獲取資源Id的方法,涉及Android針對控件資源的相關(guān)操作技巧,需要的朋友可以參考下2016-08-08