我正将手机相机中的照片添加到片段。我包括文件路径,我希望图片保存在相机目的地(MediaStore.ACTION_IMAGE_CAPTURE
)。将文件路径添加到MediaStore.ACTION_IMAGE_CAPTURE意图时遇到问题
我的问题是,启动相机并拍摄照片后,我无法返回到我的应用程序。屏幕停留在用户可以选择接受图片的位置或拍摄另一张图片。手机没有挂起或崩溃,我可以通过点击后退按钮返回到我的应用程序,但当我回到应用程序时,它没有图片。
我希望我已经明确了我的问题,如果不让我知道,我会尽力解释更好。我已附加(我认为)是代码的相关部分。让我知道是否需要再看看代码。
启动摄像头意图:
void takePic()
{
if(isExternalStorageWritable() && isExternalStorageReadable())
{
Log.w("Rakshak", "in the take pic");
File file = getPicStoragePath();
Uri uriSavedImage=Uri.fromFile(file);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
startActivityForResult(intent, CAMERA_IMAGE_ACTIVITY_REQUEST_CODE);
}
}
public File getPicStoragePath() {
Log.w("Rakshak", "in the get pic file");
File root = android.os.Environment.getExternalStorageDirectory();
File dir = new File (root.getAbsolutePath() + File.separator +"YAN");
if(!dir.exists())
dir.mkdirs();
File file = new File(dir,getPicName());
return file;
}
public String getPicName()
{
Log.w("Rakshak", "in the get pic name");
if(title.getText().toString().trim().length() == 0)
{
Log.w("Rakshak", "no title");
Calendar cal=Calendar.getInstance();//get an instance of the calendar
return String.format("%1$te %1$tB %1$tY,%1$tI:%1$tM:%1$tS %1$Tp",cal);// get the data/time when the note was created
}
else
{
return title.getText().toString().trim();
}
}
我在清单这些权限:从onActivityResult
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
的relavent位:
case CAMERA_IMAGE_ACTIVITY_REQUEST_CODE:
Log.w("Rakshak", "in the camera case");
myBitmap = data.getExtras().getParcelable("data");
photo.setVisibility(View.VISIBLE);
photo.setImageBitmap(myBitmap);
update_pic = true;
return;
有没有错误信息在LogCat中。在那里我找不到任何便条。
我得到的图片插入图像视图就好了,如果我不添加一个文件路径的相机意图。只有当我添加留在相机的“接受图片”位的文件路径时。
您正在使用fragment.InFragmentresult没有调用片段。 OnActivityResult中的FragmentActivity被调用所以在FragmentActivity(请求代码和结果代码)中调用这个被调用 – Sanket990
我有一个Log命令作为onActivityResult的第一行。所以我知道它被调用。此外,这不是onActivityResult中唯一的代码。我正在从图库中挑选一张图片,而且这种图片的效果也很好。另外,如果我不在文件路径中添加摄像机意图,我可以将图像传到我的Frgament。所以我知道onActivityResult被调用的事实。 – DrkStr