如何从调用的意图回去 [英] How to go back from calling intent

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

问题描述

我通话摄像头拍照。但我不能拍摄照片后,回到我自己原来的活动。什么问题?谢谢你。

 公共无效的addEntry(查看视图)
{
              串EntryName = RegisterName.toString();
              Toast.makeText(这一点,EntryName,Toast.LENGTH_LONG);
              意图addEntryintent =新的意图(MediaStore.ACTION_IM​​AGE_CAPTURE);
              档案文件=新的文件(getFilesDir(),EntryName);
              registeryFileUri = Uri.fromFile(文件);
              addEntryintent.putExtra(MediaStore.EXTRA_OUTPUT,registeryFileUri);
              startActivityForResult(addEntryintent,TAKE_PICTURE);

}


@覆盖
保护无效onActivityResult(INT申请code,INT结果code,意图数据){
      如果(要求code == TAKE_PICTURE)
      {
          如果(数据!= NULL)
          {
         Toast.makeText(这一点,注册成功!,Toast.LENGTH_LONG);
         ImageView的Registerimage =(ImageView的)findViewById(R.id.RegisterPicture);
         Registerimage.setImageURI(registeryFileUri);
         }

    }
  }
 

解决方案

答案

使用 appContext.getExternalCacheDir()不要忘记提及PERMISSONS。

  @覆盖
        保护无效onActivityResult(INT申请code,INT结果code,意图数据){
              如果(要求code == TAKE_PICTURE)
              {
                      如果(结果code == Activity.RESULT_OK)
                  {//如果(数据!= NULL)
                    // {
                    Toast.makeText(这一点,注册成功!,Toast.LENGTH_LONG);
                    ImageView的Registerimage =(ImageView的)findViewById(R.id.RegisterPicture);
                    Registerimage.setImageURI(registeryFileUri);
                    //}
                       }
                      其他
                         Toast.makeText(这一点,别录!,Toast.LENGTH_LONG);
             }
**android.permission.CAMERA**

检查上面的权限是否被指定在您的清单或不

注:这是更好地使用getExternalCacheDir()比getFilesDir(),如果你仍然没有得到
      图片,然后使用它。不要忘了指定的权限android.permission.WRITE_EXTERNAL_STORAG​​E如果使用getExternalCacheDir()。
 

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);
         }

    }
  }

解决方案

Answer

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天全站免登陆