Android调用系统拍照的代码:
创建Intent Intent openCameraIntent = new Intent(MediaStoreACTION_IMAGE_CAPTURE);
String imagePath = EnvironmentgetExternalStorageDirectory() + "/image" ;
设置文件路径 File file = new File(imagePath);
if(!fileexists()){
filemkdirs(); }
设置URI,指定相册拍照后保存的路径,Uri imageUri = UrifromFile(new File(imagePath, "imagejsp"));
openCameraIntentputExtra(MediaStoreEXTRA_OUTPUT, imageUri);
startActivityForResult(openCameraIntent, REQUEST_CODE_TAKING_PICTURES);
拍照完以后,文件就会保存在这个指定的目录下了。Uri 里指定了相机拍照的路径。
首先在电脑和手机上安装最新版的QQ软件(如果都已经安装,升级到最新版的QQ)。然后在手机和电脑上同时打开同一个QQ帐号,如果电脑跟手机都d出来实现手机和电脑QQ互联对话框,点击同意同步互联。这时在电脑中QQ的窗口会看到如下图标:
点击电脑QQ窗口的那个手机图标后出现下面的图标:
点击“导出手机相册”会出现下面窗口:
完成 *** 作。
由于业务需要,APP内嵌H5,需要调去系统相册和拍照,网上找了点资料,整理一下,供大家参考:
private static final int REQUEST_CAMERA =1;
private static final int REQUEST_CHOOSE =2;
private ValueCallbackmUploadMessage;
private ValueCallbackmUploadMessagesAboveL;
private UricameraUri;
//50以后的方法
webViewsetWebChromeClient(new WebChromeClient() {
@RequiresApi(api = BuildVERSION_CODESLOLLIPOP)
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback filePathCallback, FileChooserParams fileChooserParams) {
if (mUploadMessagesAboveL !=null) {
mUploadMessagesAboveLonReceiveValue(null);
mUploadMessagesAboveL =null;
}else {
mUploadMessagesAboveL = filePathCallback;
selectImage();
}
return true;
}
});
//选择和拍照,对应的string文件,可以自己写死:拍照,相册,取消
private void selectImage() {
ActionSheetcreateBuilder(this, getSupportFragmentManager())
setOtherButtonTitles(new String[]{getResources()getString(Rstringcommon_tip_photos), getResources()getString(Rstringcommon_picture)})
setCancelButtonTitle(getResources()getString(Rstringcommon_cancel))setCancelableOnTouchOutside(true)setListener(new ActionSheetActionSheetListener() {
public void onDismiss(ActionSheet actionSheet, boolean isCancel) {
if (mUploadMessage !=null) {
mUploadMessageonReceiveValue(null);
mUploadMessage =null;
}
if (mUploadMessagesAboveL !=null) {
mUploadMessagesAboveLonReceiveValue(null);
mUploadMessagesAboveL =null;
}
actionSheetdismiss();
}
@RequiresApi(api = BuildVERSION_CODESM)
public void onOtherButtonClick(ActionSheet actionSheet, int index) {
switch (index) {
case 0:
chosePicture();
break;
case 1:
setRequestCamera();
}
}
})show();
}
//拍照,添加权限申请 这个可以自己写下,我这边是项目中写好的,直接拿过来用了
public void setRequestCamera() {
permissionsBuilder =new YXTPermissionsBuilderBuilder(this)
setOnGrantedListener((requestCode, perms) -> {
openCamera();
})
setRationale4NeverAskAgain(LanguageUtilsisEnglish() Stringformat(getString(Rstringpermission_tips), getString(Rstringcommon_camera), getString(Rstringapp_name), getString(Rstringapp_name)) :
Stringformat(getString(Rstringpermission_tips), getString(Rstringapp_name), getString(Rstringcommon_camera), getString(Rstringapp_name)))
//必需
setRequestCode(ConstantsDataGET_CAMERA)
build();
permissionsBuilderrequestPermissions(ManifestpermissionCAMERA);
}
/
本地相册选择
/
private void chosePicture() {
Intent innerIntent =new Intent(IntentACTION_GET_CONTENT, androidproviderMediaStoreImagesMediaEXTERNAL_CONTENT_URI);
innerIntentsetType("image/");
Intent wrapperIntent = IntentcreateChooser(innerIntent, null);
startActivityForResult(wrapperIntent, REQUEST_CHOOSE);
}
/
打开照相机
/
private void openCamera() {
Intent intent =new Intent(MediaStoreACTION_IMAGE_CAPTURE);
String imagePaths = EnvironmentgetExternalStorageDirectory()getPath() +"/pbccrc/Images/" + (SystemcurrentTimeMillis() +"jpg");
// 必须确保文件夹路径存在,否则拍照后无法完成回调
File vFile =new File(imagePaths);
if (!vFileexists()) {
File vDirPath = vFilegetParentFile();
vDirPathmkdirs();
}else {
if (vFileexists()) {
vFiledelete();
}
}
cameraUri = FileProvidergetUriForFile(
this,
getPackageName() +"fileprovider",
vFile);
intentputExtra(MediaStoreEXTRA_OUTPUT, cameraUri);
startActivityForResult(intent, REQUEST_CAMERA);
}
/
选择照片后结束
@param data
/
private UriafterChosePic(Intent data) {
if (data !=null) {
final String path = datagetData()getPath();
if (path !=null && (pathendsWith("png") || pathendsWith("PNG") || pathendsWith("jpg") || pathendsWith("JPG"))) {
return datagetData();
}else {
ToastmakeText(this, "上传的仅支持png或jpg格式", ToastLENGTH_SHORT)show();
}
}
return null;
}
/
返回文件选择
/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (mUploadMessagesAboveL !=null) {
onActivityResultAboveL(requestCode, resultCode, intent);
}
if (mUploadMessage ==null)return;
Uri uri =null;
if (requestCode ==REQUEST_CAMERA && resultCode ==RESULT_OK) {
uri =cameraUri;
Loge("onActivityResult: " + uritoString());
}
if (requestCode ==REQUEST_CHOOSE && resultCode ==RESULT_OK) {
uri = afterChosePic(intent);
}
mUploadMessageonReceiveValue(uri);
mUploadMessage =null;
superonActivityResult(requestCode, resultCode, intent);
}
/
50以后机型 返回文件选择
@param requestCode
@param resultCode
@param data
/
private void onActivityResultAboveL(int requestCode, int resultCode, Intent data) {
Uri[] results =null;
if (requestCode ==REQUEST_CAMERA && resultCode ==RESULT_OK) {
results =new Uri[]{cameraUri};
}
if (requestCode ==REQUEST_CHOOSE && resultCode ==RESULT_OK) {
if (data !=null) {
String dataString = datagetDataString();
if (dataString !=null)
results =new Uri[]{Uriparse(dataString)};
}
}
mUploadMessagesAboveLonReceiveValue(results);
mUploadMessagesAboveL =null;
return;
}
基本都可以拿去用了,希望有帮助
以上就是关于一个关于android的问题,我通过下面的方法调用相机,可是怎么可以在拍照结束后获取照片的路径呢全部的内容,包括:一个关于android的问题,我通过下面的方法调用相机,可是怎么可以在拍照结束后获取照片的路径呢、如何在电脑上调用android手机上面的照相机、Android WebView 调用系统拍照和相册等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)