分為6.0和6.0以下兩種方法。6.0以下api不能直接調(diào)用某些方法。就像js交互一樣= =,想到這里,先貼上6.0以后js交互的方法。非常簡單
@SuppressLint("NewApi")private voidgetImgcValue() {buyWebview.evaluateJavascript("$('.shareImgUrl').attr('shareImgUrl')", newValueCallback() {@Overridepublic voidonReceiveValue(String value) {imgurl= value;}? ? });}
題外話了,下面放上檢查權(quán)限的方法。
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;
}