分为6.0和6.0以下两种方法。6.0以下api不能直接调用某些方法。就像js交互一样= =,想到这里,先贴上6.0以后js交互的方法。非常简单
@SuppressLint("NewApi")private voidgetImgcValue() {buyWebview.evaluateJavascript("$('.shareImgUrl').attr('shareImgUrl')", newValueCallback() {@Overridepublic voidonReceiveValue(String value) {imgurl= value;} });}
题外话了,下面放上检查权限的方法。
public static boolean checkPermission(Context context, String permission) {
boolean result = false;
if (Build.VERSION.SDK_INT >= 23) {
try {
Class clazz = Class.forName("android.content.Context");
Method method = clazz.getMethod("checkSelfPermission", String.class);
int rest = (Integer) method.invoke(context, permission);
if (rest == PackageManager.PERMISSION_GRANTED) {
result = true;
} else {
result = false;
}
} catch (Exception e) {
result = false;
}
} else {
PackageManager pm = context.getPackageManager();
if (pm.checkPermission(permission, context.getPackageName()) == PackageManager.PERMISSION_GRANTED) {
result = true;
}
}
return result;
}