調(diào)用系統(tǒng)相機(jī)(兼容)

新做了一個(gè)需求 ?要禁用系統(tǒng)相機(jī)外所有拍照應(yīng)用?

只能調(diào)用手機(jī)默認(rèn)的系統(tǒng)相機(jī)??

后來發(fā)現(xiàn)直接 intent.setPackage("com.android.camera"); 這樣會(huì)有問題

有一些手機(jī)默認(rèn)拍照 包名并不是?com.android.camera

小部分手機(jī),這樣會(huì)造成應(yīng)用直接暴死

于是我直接修改為以下:


? ? ? ? ?Intent intent =newIntent(MediaStore.ACTION_IMAGE_CAPTURE);//打開攝像機(jī)列表選項(xiàng)

? ? ? ? ? ?intent.putExtra("return-data", false);

? ? ? ? ? ? ? ? ?finalIntent intent_camera = getPackageManager().getLaunchIntentForPackage("com.android.camera");

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if(intent_camera !=null) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?String s = GetAction_image_capture();

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?intent.setPackage(s);

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}

? ? ? ? ? ? ? ? ? ? intent.putExtra(MediaStore.EXTRA_OUTPUT,

? ? ? ? ? ? ? ? ? Uri.fromFile(newFile(AppConfig.CAMERA_TEMP))); // AppConfig.CAMERA_TEMP 這個(gè)是保存路徑最后用.jpg結(jié)尾

? ? ? ? ? ? ? ? ? ? ?startActivityForResult(intent,CAMERA);


//獲取相機(jī)包名

private String GetAction_image_capture() {

? ? ? ? ? String Action_image_capture = "";

? ? ? ?Intent infoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

? ? ? ? ? ResolveInfo resolveInfo = getPackageManager().resolveActivity(infoIntent, 0);

? ? ? ? ? ? ? ? ? ? ? ? ?if (resolveInfo != null) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Log.d("PhotoActivity", "手機(jī)默認(rèn)相機(jī)名稱為" + resolveInfo.activityInfo.packageName);

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Action_image_capture = resolveInfo.activityInfo.packageName;}

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?return Action_image_capture;}


? ? ? 這樣直接調(diào)用系統(tǒng)相機(jī)拍照就少很多問題了 記得拍照要申請(qǐng)??

? ? ? ? ?Manifest.permission.WRITE_EXTERNAL_STORAGE

? ? ? ? ? ?Manifest.permission.CAMERA

? ? ? ? ? ? ? ? ? ? ? ?這兩個(gè)權(quán)限?

```? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 最后 good luck

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容