<view class="mpage">
<view>
<input type="text" placeholder="app package_name" value="{{package_name}}" bindinput="changePackageName"/>
</view>
<view style="font-size: 50px;" bindtap="testInstallApp">hello</view>
</view>
const app = getApp();
Page({
data: {
info: {},
// package_name:"com.cshchxm.app",
package_name:"com.zhihuiyun.app",
},
onPreviewTap: function (e) {
let src = e.currentTarget.dataset.src;
app.onPreviewTap(src);
},
changePackageName(e){
this.setData({
package_name:e.detail.value
});
},
testInstallApp(){
//app.alert(this.data.package_name);
wx.miniapp.loadNativePlugin({
pluginId: 'wx366177b29ccb8b34',
success: (plugin) => {
console.log('load plugin success')
const ret = plugin.isInstallApp(this.data.package_name)
console.log('mySyncFunc ret:', ret)
app.alert(ret);
/* plugin.myAsyncFuncwithCallback({ package_name: 'com.cshchxm.app'}, (ret) => {
//console.log('myAsyncFuncwithCallback ret:', ret);
app.alert(JSON.stringify(ret));
}) */
},
fail: (e) => {
app.alert("e");
}
})
},
onLoad(options) {
wx.setNavigationBarTitle({
title: '当前页面'
});
},
checkPageLogin() {
this.checkLogin(user => {
this.setData({
user
});
}, '/pages/test/mission/mission');
},
onShareAppMessage() {
return {
same_share: true,
title: '标题',
path: '/pages/test/test'
};
},
onShareTimeline() {
return {
same_share: true,
title: '标题',
query: 'id=2'
};
},
// onShareAppMessage(options) {
// const {
// target
// } = options;
// let id = target.dataset.id;
// return {
// same_share: true,
// title: '动态详情',
// path: `/niche/dongtaidetails/dongtaidetails?id=${id}`
// };
// },
// onShareTimeline(options) {
// const {
// target
// } = options;
// let id = target.dataset.id;
// return {
// same_share: true,
// title: '动态详情',
// query: `id=${id}`
// };
// },
onReachBottom() {
this.loadListData();
},
loadListData() {
if (this.data.list.over || this.data.list.load)
return;
this.setData({
[`list.load`]: true,
});
let param = {
page: this.data.list.page,
length: this.data.list.length
};
app.api.apiTestGetmock(param)
.then(res => {
this.setData({
img_root: res.other.img_root
});
this.dealList(res.data, this.data.list.page);
})
.catch(err => {
app.tips(err);
});
},
resetListData() {
this.setData({
list: {
page: 1,
length: 10,
over: false,
load: false,
none: false,
data: []
},
});
},
ooopp(){
let url = 'https://zhyframe.fzh.fun/addons/zhyshop_sun/front/?uid=1023#/pages/home/home'
let str = encodeURIComponent(url);
wx.navigateTo({
url:`/base/webview/webview?title=首页&id=${str}`,
})
},
onIUIU(){
wx.chooseLocation({
// latitude:39.906217,
// longitude:116.3912757,
latitude:'',
longitude:'',
success:(res)=>{
console.log(res);
}
});
// wx.openLocation({
// latitude:39.906217,
// longitude:116.3912757,
// });
},
TapopenLocation(e){
wx.getLocation({
type: 'wgs84',
success(res) {
wx.showModal({
title: '',
content: `latitude:${res.latitude},longitude:${res.longitude}`,
complete: (res) => {
if (res.cancel) {
}
if (res.confirm) {
}
}
})
app.openLocation({
latitude:res.latitude,
longitude: res.longitude,
})
},
})
},
TapchooseLocation(e){
wx.getLocation({
type: 'gcj02',
success(res) {
app.chooseLocation({
latitude:res.latitude,
longitude: res.longitude,
})
},
})
},
});
package com.donut.wx366177b29ccb8b34
import android.app.Activity
import android.app.Application
import com.tencent.luggage.wxa.SaaA.plugin.NativePluginInterface
import com.tencent.luggage.wxa.SaaA.plugin.NativePluginBase
import com.tencent.luggage.wxa.SaaA.plugin.SyncJsApi
import com.tencent.luggage.wxa.SaaA.plugin.AsyncJsApi
import org.json.JSONObject
import java.lang.reflect.Method
import android.content.pm.PackageManager
class TestNativePlugin: NativePluginBase(), NativePluginInterface {
private val TAG = "TestNativePlugin"
override fun getPluginID(): String {
android.util.Log.e(TAG, "getPluginID")
return BuildConfig.PLUGIN_ID
}
@SyncJsApi(methodName = "mySyncFunc")
fun test(data: JSONObject?, activity: Activity): String {
android.util.Log.i(TAG, data.toString())
val componentName = activity.componentName.toString()
android.util.Log.i(TAG, componentName)
return "test"
}
@AsyncJsApi(methodName = "myAsyncFuncwithCallback")
fun testAsync(data: JSONObject?, callback: (data: Any) -> Unit, activity: Activity) {
android.util.Log.i(TAG, data.toString())
// 有需要的时候向 js 发送消息
val values1 = HashMap<String, Any>()
values1["status"] = "testAsync start"
this.sendMiniPluginEvent(values1)
callback("async testAsync")
}
@SyncJsApi(methodName = "isInstallApp")
fun testIsInstallApp(data: JSONObject?, activity: Activity): String {
val package_name=data!!.getString("package_name");
try {
// val packageManager = packageManager
// val applicationInfo = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
// applicationInfo.metaData?.getString(key)
val clazz = Class.forName("android.app.ActivityThread")
val method: Method = clazz.getMethod("currentApplication")
val mApplication = method.invoke(null) as Application
val applicationInfo = mApplication.packageManager.getPackageInfo(
package_name,
PackageManager.GET_ACTIVITIES
)
//applicationInfo.metaData?.getString(key);
return "ok"
} catch (e: PackageManager.NameNotFoundException) {
return package_name;
}
}
}
"mini-plugin": {
"android": [
{
"open": true,
"pluginId": "wx366177b29ccb8b34",
"pluginVersion": "0.1.2"
}
]
}