提交 950ee41d 编写于 作者: 杜庆泉's avatar 杜庆泉

android 新增 集成jar的示例

上级 be92050c
......@@ -18,7 +18,7 @@
</view>
</template>
<script lang="ts">
import { gotoDemoActivity } from "@/uni_modules/uts-nativepage";
import { gotoDemoActivity,sayHelloFromJar } from "@/uni_modules/uts-nativepage";
import { getBatteryInfo, GetBatteryInfoOptions } from "@/uni_modules/uts-getbatteryinfo";
type Page = {
......@@ -66,6 +66,9 @@
pages: [{
name: "自定义activity(需自定义基座)",
function: "testGotoDemoActivity"
},{
name: "调用jar中的方法",
function: "testNativeJar"
}] as Page[]
}
] as ListItem[],
......@@ -93,6 +96,8 @@
break
case 'testGotoDemoActivity':
this.testGotoDemoActivity()
case 'testNativeJar':
this.testNativeJar()
break
}
return
......@@ -112,6 +117,13 @@
}
} as GetBatteryInfoOptions)
},
testNativeJar() {
let ret = sayHelloFromJar();
uni.showToast({
icon: 'none',
title: '来自jar中的返回值:' + ret
})
},
testGotoDemoActivity() {
let ret = gotoDemoActivity();
if (!ret) {
......
......@@ -36,6 +36,30 @@ import Log from 'android.util.Log';
import File from 'java.io.File';
import Uri from 'android.net.Uri';
export * from './CustomAccessibilityService.uts'
import SayHelloTest from 'com.test.sayhello.SayHelloTest'
export function sayHelloFromJar(): string {
// 这里的逻辑是为了判断 当前的自定义activity 是否注册了,并以此为条件判断是否是自定义基座
let hasXActivityIntegration = true
try{
let packageManager = UTSAndroid.getUniActivity()!.getPackageManager();
let intent = new Intent(UTSAndroid.getUniActivity(),DemoActivity().javaClass);
let resolveInfo = packageManager.queryIntentActivities(intent,0);
console.log(resolveInfo.size)
if(resolveInfo.size == 0){
hasXActivityIntegration = false;
}
}catch(e:Exception){
console.log(e);
hasXActivityIntegration = false;
}
if(!hasXActivityIntegration){
return "需要在自定义基座运行";
}
return SayHelloTest().say()
}
export class AppHookProxy implements UTSAndroidHookProxy {
override onCreate(application: Application) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册