Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android中无法获得意图的价值_Android_Image_Android Intent - Fatal编程技术网

在android中无法获得意图的价值

在android中无法获得意图的价值,android,image,android-intent,Android,Image,Android Intent,我想拍一张照片,但是 onActivityResult(int-requestCode、int-resultCode、Intent-data) 当你说这很有趣的时候。意图部分为空, 但是在 startActivityForResult(意图、捕获、图像、活动、请求、代码) 我得到了intent=intent{act=android.media.action.IMAGE\u捕获(有附加功能)} 我的代码是 public class MainActivity extends Activity {

我想拍一张照片,但是

onActivityResult(int-requestCode、int-resultCode、Intent-data)

当你说这很有趣的时候。意图部分为空, 但是在

startActivityForResult(意图、捕获、图像、活动、请求、代码)

我得到了
intent=intent{act=android.media.action.IMAGE\u捕获(有附加功能)}

我的代码是

 public class MainActivity extends Activity {

    private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
    //private static final int RESULT_OK = -1;
    private static final int MEDIA_TYPE_IMAGE = 1;

    public static String s = null;

    private Uri fileUri;
    private static Intent intent;

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

          // create Intent to take a picture and return control to the calling application
         intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
        intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name

        // start the image capture Intent
        startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
        //onActivityResult(CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE, int resultCode, intent)
    }


    private Uri getOutputMediaFileUri(int type) {
        // TODO Auto-generated method stub
          return Uri.fromFile(getOutputMediaFile(type));
    }

    /** Create a File for saving an image or video */
    @SuppressLint("SimpleDateFormat")
    private static File getOutputMediaFile(int type){
        // To be safe, you should check that the SDCard is mounted
        // using Environment.getExternalStorageState() before doing this.

        File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
                  Environment.DIRECTORY_PICTURES), "MyCameraApp");
        // This location works best if you want the created images to be shared
        // between applications and persist after your app has been uninstalled.

        // Create the storage directory if it does not exist
        if (! mediaStorageDir.exists()){
            if (! mediaStorageDir.mkdirs()){
                Log.d("IWMP-Images", "failed to create directory");
                return null;
            }
        }

        // Create a media file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new java.util.Date());
        File mediaFile;
        if (type == MEDIA_TYPE_IMAGE){
            mediaFile = new File(mediaStorageDir.getPath() + File.separator +
            "IMG_"+ timeStamp + ".jpg");
        }  else {
            return null;
        }

        return mediaFile;

    }



    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
            if (resultCode == RESULT_OK) {
                // Image captured and saved to fileUri specified in the Intent
// Main Thing here.. data.getData = null coz data = null
   Toast.makeText(this, "Image saved to:\n" + data.getData(),Toast.LENGTH_LONG).show();
                //s =data.getData().toString();
                Intent intent2 = new Intent(MainActivity.this,MainActivity2.class);

                intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
                getApplicationContext().startActivity(intent2);



            } else if (resultCode == RESULT_CANCELED) {
                // User cancelled the image capture
            } else {
                // Image capture failed, advise user
                 Toast.makeText(this, "Image NOT saved ", Toast.LENGTH_LONG).show();
            }
        }
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

   }

读取意图的代码在哪里?我使用的是data.getData()func。。获取URI。!!