cocos2d-js icon indicating copy to clipboard operation
cocos2d-js copied to clipboard

Add native class refrection

Open jianglong0156 opened this issue 9 years ago • 3 comments

add a importClass mehtod to get the native class like this to get the device.uuid:

var Settings= plus.android.importClass("android.provider.Settings");

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);

var action = new Intent(Intent.ACTION_MAIN);
action.setComponent(main.getComponentName());
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT,action);

main.sendBroadcast(shortcut);

jianglong0156 avatar May 04 '15 09:05 jianglong0156

the docuemt http://ask.dcloud.net.cn/article/88

jianglong0156 avatar May 04 '15 09:05 jianglong0156

+1

zj8487 avatar May 04 '15 11:05 zj8487

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.

zhaijialong avatar May 04 '15 12:05 zhaijialong