ActivityNotFoundException, image capturing?

霸气de小男生 提交于 2019-12-01 13:12:48

问题


I have released an App which user can take photo in it.I do this to capturing photo:

File file = new File( _path );
Uri outputFileUri = Uri.fromFile( file );   
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );      
startActivityForResult( intent, 0 );

and also I added this permission to manifest:

<uses-permission android:name="android.permission.CAMERA" />

I tested my App on Android2.3.5 and Android3.0,and it works fine.But when I run my App on Android4.0.3,it crashes:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.media.action.IMAGE_CAPTURE (has extras) }

How I can solve this problem?


回答1:


several things can be happened

  1. there might not be any camera in the device
  2. there is no sd card in the device

does your case meet any of the above?




回答2:


Check if your

1.Tablet has camera (if your using tablet). 2. A phone has camera 3. No SD card installed.

Add the below to manifest.

   <uses-feature android:name="android.hardware.camera" />

Will prevent apps being downloaded from google play. http://developer.android.com/google/play/filters.html

Also Check http://developer.android.com/guide/topics/manifest/uses-feature-element.html

To check if your device has camera.

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.main);

    Context context = this;
    PackageManager packageManager = context.getPackageManager();

    // if device support camera?
    if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        //yes
        Log.i("camera", "This device has camera!");
    }else{
        //no
        Log.i("camera", "This device has no camera!");
    }


}
}


来源:https://stackoverflow.com/questions/15565390/activitynotfoundexception-image-capturing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!