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

android 新增 集成jar的示例

上级 be92050c
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
</view> </view>
</template> </template>
<script lang="ts"> <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"; import { getBatteryInfo, GetBatteryInfoOptions } from "@/uni_modules/uts-getbatteryinfo";
type Page = { type Page = {
...@@ -66,6 +66,9 @@ ...@@ -66,6 +66,9 @@
pages: [{ pages: [{
name: "自定义activity(需自定义基座)", name: "自定义activity(需自定义基座)",
function: "testGotoDemoActivity" function: "testGotoDemoActivity"
},{
name: "调用jar中的方法",
function: "testNativeJar"
}] as Page[] }] as Page[]
} }
] as ListItem[], ] as ListItem[],
...@@ -93,6 +96,8 @@ ...@@ -93,6 +96,8 @@
break break
case 'testGotoDemoActivity': case 'testGotoDemoActivity':
this.testGotoDemoActivity() this.testGotoDemoActivity()
case 'testNativeJar':
this.testNativeJar()
break break
} }
return return
...@@ -112,6 +117,13 @@ ...@@ -112,6 +117,13 @@
} }
} as GetBatteryInfoOptions) } as GetBatteryInfoOptions)
}, },
testNativeJar() {
let ret = sayHelloFromJar();
uni.showToast({
icon: 'none',
title: '来自jar中的返回值:' + ret
})
},
testGotoDemoActivity() { testGotoDemoActivity() {
let ret = gotoDemoActivity(); let ret = gotoDemoActivity();
if (!ret) { if (!ret) {
......
...@@ -36,6 +36,30 @@ import Log from 'android.util.Log'; ...@@ -36,6 +36,30 @@ import Log from 'android.util.Log';
import File from 'java.io.File'; import File from 'java.io.File';
import Uri from 'android.net.Uri'; import Uri from 'android.net.Uri';
export * from './CustomAccessibilityService.uts' 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 { export class AppHookProxy implements UTSAndroidHookProxy {
override onCreate(application: Application) { override onCreate(application: Application) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册