未找到Android Studio Camera Use Activity

时间:2016-12-03 21:26:31

标签: java android android-studio fatal-error

嗨在使用Android工作室构建一个简单的Android应用程序,使用我的设备相机捕获图像并将其存储到图库,但我得到这个错误:。

$args = array(
    'category_name' => 'courses',
    'orderby'       => 'menu_order',
    'order'         => 'ASC',
    'meta_query' => array(
        array(
            'key'     => 'front_page',
            'value'   => 'yes',
            'compare' => 'LIKE',
        ))

);

$the_query = new WP_Query( $args );

我的代码是:

 FATAL EXCEPTION: main
                                                                              Process: com.industry.onelove.camerause, PID: 7897
                                                                              android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.media.action..IMAGE_CAPTION (has extras) }
                                                                                  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1809)
                                                                                  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1523)
                                                                                  at android.app.Activity.startActivityForResult(Activity.java:4224)
                                                                                  at android.app.Activity.startActivityForResult(Activity.java:4183)
                                                                                  at com.industry.onelove.camerause.HomeActivity.takePhoto(HomeActivity.java:74)
                                                                                  at com.industry.onelove.camerause.HomeActivity.access$000(HomeActivity.java:22)
                                                                                  at com.industry.onelove.camerause.HomeActivity$1.onClick(HomeActivity.java:42)
                                                                                  at android.view.View.performClick(View.java:5610)
                                                                                  at android.view.View$PerformClick.run(View.java:22260)
                                                                                  at android.os.Handler.handleCallback(Handler.java:751)
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                  at android.os.Looper.loop(Looper.java:154)
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

我已经导入了我的清单:

public class HomeActivity extends Activity {

    private Button button;
    private static String logtag = "CameraAp";
    private static  int Take_pic = 1 ;
    private Uri imageUri;

    //ONCREATE
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        button =(Button) findViewById(R.id.button);
        button.setOnClickListener(cameraListener);
    }
    //BUTTONS LISTENER
    private View.OnClickListener cameraListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            takePhoto(v);
        }
    };

    String mCurrentPhotoPath;

    private File createImageFile() throws IOException {//CREATE FILEPATH WITH DATEFORMAT USE (FROM ANDROID API)
        // Create an image file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "JPEG_" + timeStamp + "_";
        File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        File image = File.createTempFile(
                imageFileName,
                ".jpg",
                storageDir
        );

        // Save a file: path for use with ACTION_VIEW intents
        mCurrentPhotoPath = image.getAbsolutePath();
        return image;
    }

    private void takePhoto(View v){
        Intent intent = new Intent("android.media.action..IMAGE_CAPTION");
        try {
            createImageFile();
        }catch(IOException io){
            Log.e(logtag, io.toString());
        }
        File photo = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),mCurrentPhotoPath);
        imageUri = Uri.fromFile(photo);
        intent.putExtra(MediaStore.EXTRA_OUTPUT , imageUri);
        startActivityForResult(intent , Take_pic);
    }

    @Override
    protected void onActivityResult( int requestCode , int resultCode , Intent intent)
    {
        super.onActivityResult(requestCode , resultCode, intent);
        if(resultCode == Activity.RESULT_OK){
            Uri selectedImage = imageUri;
            getContentResolver().notifyChange(selectedImage,null);

            ImageView imageView = (ImageView) findViewById(R.id.image_view);
            ContentResolver cr = getContentResolver();
            Bitmap bitmap;
            try{
                bitmap = MediaStore.Images.Media.getBitmap(cr , selectedImage);//CREATE THE BITMAP
                imageView.setImageBitmap(bitmap);//GIVE IMAGE TO IMAGEVIEW AND SHOW TO USER
                MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, mCurrentPhotoPath , "auga me mpeikon");//SAVE IMAGE TO GALERY
            }catch(Exception exp){
                Log.e(logtag, exp.toString());
            }
            Toast.makeText(HomeActivity.this , selectedImage.toString(),Toast.LENGTH_LONG).show();

        }
    }


    //IN ORDER TO SAVE THE IMAGE WE CAN ALSO USE THE API READY FUCTION WHICH SAVES THE FILE TO THE DIRECTORY THROUGH OUR STRING CURRENTPATH
    private void galleryAddPic() {
        Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        File f = new File(mCurrentPhotoPath);
        Uri contentUri = Uri.fromFile(f);
        mediaScanIntent.setData(contentUri);
        this.sendBroadcast(mediaScanIntent);
    }
}

有谁知道为什么?

1 个答案:

答案 0 :(得分:2)

Intent intent = new Intent("android.media.action..IMAGE_CAPTION");

这不是有效的Intent操作。或者,至少,您的设备上没有支持它的应用程序。

也许你的意思是:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);