【发布时间】:2016-04-26 02:39:39
【问题描述】:
关于在棒棒糖和更高版本中从相机捕获图像时,onActivityResult 上的结果数据为空。
launchCamera();
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
((MyWebViewActivity) context).fileUri = CommonUtils.getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, ((MyWebViewActivity) context).fileUri);
((MyWebViewActivity) context).startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
@Override
onActivityResult(int requestCode, int resultCode, Intent data);
if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
if(fileUri!=null){
file_path = fileUri.getPath();
System.out.println("file-path---=" + file_path);
}else{
Toast.makeText(this, "Please try again", Toast.LENGTH_LONG).show();
}
if(!CommonUtils.isEmpty(file_path)){
}
} else if (resultCode == RESULT_CANCELED) {
// "User cancelled image capture",
} else {
// failed to capture image
}
}
getOutputMediaFileUri()
File file = getOutputMediaFile(type);
if (file != null) {
return Uri.fromFile(file);
}
return null;
getOutputMediaFile()
// External sdcard location
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "My Images");
// Create the storage directory if it does not exist
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
return null;
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
File mediaFile;
System.out.println("mediaStorageDir==" + mediaStorageDir);
if (type == MEDIA_TYPE_IMAGE) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".png");
} else if (type == MEDIA_TYPE_VIDEO) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator + "VID_" + timeStamp + ".mp4");
} else {
return null;
}
return mediaFile;
【问题讨论】:
-
“在不询问用户的情况下更新应用程序” - 非常。坏的。主意。会让我立即卸载并向 Google 报告。
-
先生,在通过警报询问是否更新之后,您实际上误会了我,然后我希望它自动更新其余的东西@Fildor
-
我明白了。那么,您只想绕过 Play 商店。用户仍有能力确认。是否有特定的理由避免使用 Play 商店? (只是好奇)
-
Android Developer Site 始终是此类信息的非常好的来源。
-
如果没有存储卡,你可以用它来存储在你设备的内存中:PATH=android.os.Environment.getDataDirectory().toString()+"/data/your.package.name /下载/"
标签: android android-intent intentfilter android-camera-intent