Open jianglong0156 opened 9 years ago
the docuemt http://ask.dcloud.net.cn/article/88
+1
Looks cool, but really need too much work to achieve this feature. It's very similar to NativeScript
, and you can find how they implement this feature in https://github.com/NativeScript/android-runtime.
I think a simpler and easier way is to implement the addJavascriptInterface
just like Android SDK's webview which can do pretty much the same thing.
http://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface(java.lang.Object, java.lang.String)
BTW, egret also has something very similar to the addJavascriptInterface
.
add a importClass mehtod to get the native class like this to get the device.uuid:
console.log(Settings.Secure.getString(mainActivity.getContentResolver(),Settings.Secure.ANDROID_ID));
create the icon in deskop:
Intent = plus.android.importClass("android.content.Intent"); // create icon var shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); // set icon name shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "test icon"); // set no repeat shortcut.putExtra("duplicate",false); // set icon var iconPath = plus.io.convertLocalFileSystemURL("/icon.png"); var bitmap = BitmapFactory.decodeFile(iconPath); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON,bitmap);