如何从呼叫意图返回 [英] How to go back from calling intent

查看:26
本文介绍了如何从呼叫意图返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打电话给相机拍照.但拍完照片后,我无法回到自己原来的活动中.有什么问题?谢谢.

I call camera to take a picture. But I cannot go back to my own original activity after taking the picture. What's the problem? Thank you.

    public void addEntry(View view)
{
              String EntryName=RegisterName.toString();
              Toast.makeText(this, EntryName, Toast.LENGTH_LONG);
              Intent addEntryintent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
              File file = new File(getFilesDir(),EntryName);
              registeryFileUri = Uri.fromFile(file);
              addEntryintent.putExtra(MediaStore.EXTRA_OUTPUT, registeryFileUri);
              startActivityForResult(addEntryintent,TAKE_PICTURE);         

}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (requestCode == TAKE_PICTURE) 
      {
          if (data != null)
          {   
         Toast.makeText(this, "Successfully Registered!", Toast.LENGTH_LONG);
         ImageView Registerimage= (ImageView)findViewById(R.id.RegisterPicture);
         Registerimage.setImageURI(registeryFileUri);
         }

    }
  }

推荐答案

回答

使用 appContext.getExternalCacheDir() 并且不要忘记提及权限.

Use appContext.getExternalCacheDir() and don't forget to mention permissons.

    @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
              if (requestCode == TAKE_PICTURE) 
              {
                      if(resultCode==Activity.RESULT_OK)
                  { //if (data != null)
                    //{   
                    Toast.makeText(this, "Successfully Registered!", Toast.LENGTH_LONG);
                    ImageView Registerimage= (ImageView)findViewById(R.id.RegisterPicture);
                    Registerimage.setImageURI(registeryFileUri);
                    //}
                       }
                      else
                         Toast.makeText(this, "Not Registered!", Toast.LENGTH_LONG);
             }  
**"android.permission.CAMERA"**     

Check whether the above permission is specified in your manifest or not

Note: It's better to use getExternalCacheDir() than getFilesDir() if you still dont get the 
      image then use that. Dont forgot to specify the permission "android.permission.WRITE_EXTERNAL_STORAGE" if you use the getExternalCacheDir().

这篇关于如何从呼叫意图返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆