新做了一個(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)限?