android判断clipdata否为uri,android7.0 本地打包后,相机调起失败 exposed beyond app through ClipData.Item.getUri()...

这个问题,我也问了,不过貌似都没有人解决,最后没办法,自己搞定了!说下我的思路,顺便直接上代码,有兴趣想继续深究的或者想互相学习的,可以加入这个QQ群 : 488505459

1.既然是本地打包,调不到,那为啥不换个思路,查一下android 7.0 调用摄像头的问题呢?这个网上有说明的,都大同小异,我就不说明了!

你可以去看下,官方提供的 调用摄像头的代码 camera.jar(.class 文件怎么查看,工具建议使用 jd-gui.exe),你会发现(大概在83行位置) Intent localIntent = new Intent("android.media.action.IMAGE_CAPTURE"); Uri localUri = Uri.fromFile((File)localObject); localIntent.putExtra("output", localUri); 这个是统一的,并没有区分 android版本号,所以问题就在这啦。

也许你会想办法,像在这里加入几行代码,区分版本号,但是就我实验的结果,貌似官方提供的camera.jar 是加过密的,而且反编译出来的东西有很多错误!所以,你既然已经本地打包了,说明你肯定是

要自己开发第三方插件,都自己开发第三方插件了,为啥不换个思路,掉摄像头的代码,自己来写呢?顺便提一下,关于如何开发第三方插件,如何5跳原生,原生跳h5 ,我写了一篇博客,可能不是太详细,但大家可以看下 http://blog.csdn.net/u010978381 。

4.总共涉及到两个类,一个接口类,这个开发第三方插件必须的,涉及到的代码:

//调用摄像头

public void PluginGetCameraFunction(final IWebview pWebview, JSONArray array) {

final String CallBackID = array.optString(0);

final IApp localIApp = pWebview.obtainFrameView().obtainApp();

final JSONArray newArray = new JSONArray();

final String str1=array.optString(1); //文件名称

PermissionUtil.usePermission(localIApp.getActivity(), false, "CAMERA", new PermissionUtil.StreamPermissionRequest(localIApp)

{

public void onGranted(String paramAnonymousString) {

try {

//Object localObject = new File(pWebview.getContext().getExternalCacheDir(), "_doc/output_image.jpg");

final Object localObject = new File(pWebview.getContext().getExternalCacheDir(), str1);

final File localFile = ((File)localObject).getParentFile();

if (!localFile.exists()) {

localFile.mkdirs();

}

localIApp.registerSysEventListener(new ISysEventListener()

{

public boolean onExecute(ISysEventListener.SysEventType paramAnonymous2SysEventType, Object paramAnonymous2Object) {

Object[] arrayOfObject = (Object[])paramAnonymous2Object;

int i = ((Integer)arrayOfObject[0]).intValue();

int j = ((Integer)arrayOfObject[1]).intValue();

if ((paramAnonymous2SysEventType == ISysEventListener.SysEventType.onActivityResult) &&

(i == a.a))

{

if (j == -1) {

String str=((File)localObject).getAbsolutePath();

newArray.put(str);

JSUtil.execCallback(pWebview, CallBackID, newArray, JSUtil.OK, false);

} else {

String str = DOMException.toJSON(11, "resultCode is wrong");

newArray.put(str);

JSUtil.execCallback(pWebview, CallBackID, newArray, JSUtil.ERROR, false);

}

localIApp.unregisterSysEventListener(this, paramAnonymous2SysEventType);

}

return false;

}

}, ISysEventListener.SysEventType.onActivityResult);

int currentapiVersion = android.os.Build.VERSION.SDK_INT;

Intent localIntent = new Intent("android.media.action.IMAGE_CAPTURE");

if (currentapiVersion<24){

Uri localUri = Uri.fromFile((File)localObject);

localIntent.putExtra("output", localUri);

pWebview.getActivity().startActivityForResult(localIntent, a.a);

}else {

ContentValues contentValues = new ContentValues(1);

contentValues.put(MediaStore.Images.Media.DATA, ((File)localObject).getAbsolutePath());

Uri uri = pWebview.getContext().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,contentValues);

localIntent.putExtra("output", uri);

pWebview.getActivity().startActivityForResult(localIntent, a.a);

}

} catch (Exception localException) {

}

}

public void onDenied(String paramAnonymousString)

{

String str = DOMException.toJSON(11, "No Permission");

newArray.put(str);

JSUtil.execCallback(pWebview, CallBackID, newArray, JSUtil.OK, false);

}

});

}

第二个类 a.java

/**

Created by jwj on 2017/9/13.

*/

import android.hardware.Camera;

import io.dcloud.common.adapter.util.DeviceInfo;

import java.util.List;

class a

{

protected static int a = 1;

protected static int b = 2;

List c = null;

List d = null;

List e = null;

a(int paramInt)

{

try

{

Camera localCamera = null;

if ((paramInt == 2) && (DeviceInfo.sDeviceSdkVer >= 9)) {

for (int i = 0; i < Camera.getNumberOfCameras(); i++) {

Camera.CameraInfo localCameraInfo = new Camera.CameraInfo();

Camera.getCameraInfo(i, localCameraInfo);

if (localCameraInfo.facing == 1) {

localCamera = Camera.open(i);

break;

}

}

}

if (localCamera == null) {

localCamera = Camera.open();

}

if (DeviceInfo.sDeviceSdkVer >= 11) {

this.c = localCamera.getParameters().getSupportedVideoSizes();

}

this.e = localCamera.getParameters().getSupportedPictureSizes();

if (DeviceInfo.sDeviceSdkVer >= 8) {

this.d = localCamera.getParameters().getSupportedPictureFormats();

}

localCamera.release();

} catch (Exception localException) {

localException.printStackTrace();

}

}

protected String a()

{

String str = "(function(){return{supportedImageResolutions : %s,supportedVideoResolutions : %s,supportedImageFormats : %s,supportedVideoFormats : %s};})();";

String[] arrayOfString = d();

str = String.format(str, new Object[] { c(), b(), arrayOfString[0], arrayOfString[1] });

return str;

}

private String b()

{

String str = "[]";

if ((this.c != null) && (DeviceInfo.sDeviceSdkVer >= 11)) {

List localList = this.c;

str = b(localList);

}

return str;

}

private String c()

{

String str = "[]";

if (this.e != null) {

List localList = this.e;

str = b(localList);

}

return str;

}

private String[] d()

{

String[] arrayOfString = null;

if (this.d != null) {

List localList = this.d;

arrayOfString = a(localList);

}

if (arrayOfString == null) {

arrayOfString = new String[2];

arrayOfString[0] = "['jpg']";

arrayOfString[1] = "['mp4']";

}

return arrayOfString;

}

private String[] a(List paramList)

{

String[] arrayOfString = new String[2];

arrayOfString[0] = "['jpg']";

arrayOfString[1] = "['mp4']";

return arrayOfString;

}

private String b(List paramList)

{

String str = "[]";

int i = paramList.size();

if ((paramList != null) && (i > 1)) {

StringBuffer localStringBuffer = new StringBuffer();

localStringBuffer.append("[");

for (int j = 0; j < i; j++) {

localStringBuffer.append("'" + ((Camera.Size)paramList.get(j)).width + "*" + ((Camera.Size)paramList.get(j)).height + "'");

if (j != i - 1) {

localStringBuffer.append(",");

}

}

localStringBuffer.append("]");

str = localStringBuffer.toString();

}

return str;

}

}

前台接受的代码,我们仍然是在 function getImage(obj) {}方法里来完成,不过此时的代码是这样

plus.plugintest.PluginGetCameraFunction("_doc/"+obj+".jpg", function(e) {

var s = e[0] + "?version=" + new Date().getTime();

document.getElementById(obj).src = s;

},function(s){

plus.ui.toast("error:" + s.message);

});

"_doc/"+obj+".jpg" 这个表示图片名称,自己传递到后台的! 因为是在开发项目,所以写的很匆忙,有些代码可能冗余,大家见谅一下呀,最后说一句,欢迎加入QQ群,一起学习呀!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值