Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
6e619231
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1595
Star
27
Fork
9
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
Hello UTS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
6e619231
编写于
8月 27, 2024
作者:
杜庆泉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加 混编kotlin 调用 so示例
上级
b10d4cca
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
98 addition
and
4 deletion
+98
-4
pages/SystemAPI/SystemAPI.uvue
pages/SystemAPI/SystemAPI.uvue
+18
-2
uni_modules/uts-nativepage/utssdk/app-android/NativeLib.kt
uni_modules/uts-nativepage/utssdk/app-android/NativeLib.kt
+18
-0
uni_modules/uts-nativepage/utssdk/app-android/index.uts
uni_modules/uts-nativepage/utssdk/app-android/index.uts
+62
-2
uni_modules/uts-nativepage/utssdk/app-android/libs/arm64-v8a/libnativelib.so
...ivepage/utssdk/app-android/libs/arm64-v8a/libnativelib.so
+0
-0
uni_modules/uts-nativepage/utssdk/app-android/libs/armeabi-v7a/libnativelib.so
...epage/utssdk/app-android/libs/armeabi-v7a/libnativelib.so
+0
-0
uni_modules/uts-nativepage/utssdk/app-android/libs/x86/libnativelib.so
...ts-nativepage/utssdk/app-android/libs/x86/libnativelib.so
+0
-0
uni_modules/uts-nativepage/utssdk/app-android/libs/x86_64/libnativelib.so
...nativepage/utssdk/app-android/libs/x86_64/libnativelib.so
+0
-0
未找到文件。
pages/SystemAPI/SystemAPI.uvue
浏览文件 @
6e619231
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
</view>
</view>
</template>
</template>
<script lang="ts">
<script lang="ts">
import { gotoDemoActivity,sayHelloFromJar } from "@/uni_modules/uts-nativepage";
import { gotoDemoActivity,sayHelloFromJar
,sayHelloFromSO
} from "@/uni_modules/uts-nativepage";
import { getBatteryInfo, GetBatteryInfoOptions } from "@/uni_modules/uts-getbatteryinfo";
import { getBatteryInfo, GetBatteryInfoOptions } from "@/uni_modules/uts-getbatteryinfo";
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
import {
import {
...
@@ -95,6 +95,9 @@
...
@@ -95,6 +95,9 @@
},{
},{
name: "调用jar中的方法",
name: "调用jar中的方法",
function: "testNativeJar"
function: "testNativeJar"
},{
name: "调用so中的方法",
function: "testNativeSO"
}] as Page[]
}] as Page[]
}
}
] as ListItem[],
] as ListItem[],
...
@@ -127,9 +130,13 @@
...
@@ -127,9 +130,13 @@
break
break
case 'testGotoDemoActivity':
case 'testGotoDemoActivity':
this.testGotoDemoActivity()
this.testGotoDemoActivity()
break
case 'testNativeJar':
case 'testNativeJar':
this.testNativeJar()
this.testNativeJar()
break
break
case 'testNativeSO':
this.testNativeSO()
break
}
}
return
return
}
}
...
@@ -226,7 +233,16 @@
...
@@ -226,7 +233,16 @@
icon: 'none',
icon: 'none',
title: '来自jar中的返回值:' + ret
title: '来自jar中的返回值:' + ret
})
})
},
},
testNativeSO() {
let ret = sayHelloFromSO();
uni.showToast({
icon: 'none',
title: '来自so中的返回值:' + ret
})
},
testGotoDemoActivity() {
testGotoDemoActivity() {
let ret = gotoDemoActivity();
let ret = gotoDemoActivity();
if (!ret) {
if (!ret) {
...
...
uni_modules/uts-nativepage/utssdk/app-android/NativeLib.kt
0 → 100644
浏览文件 @
6e619231
package
uts.sdk.modules.utsNativepage
class
NativeLib
{
/**
* A native method that is implemented by the 'nativelib' native library,
* which is packaged with this application.
*/
external
fun
stringFromJNI
():
String
companion
object
{
// Used to load the 'nativelib' library on application startup.
init
{
System
.
loadLibrary
(
"nativelib"
)
}
}
}
uni_modules/uts-nativepage/utssdk/app-android/index.uts
浏览文件 @
6e619231
...
@@ -19,7 +19,7 @@ import Toast from 'android.widget.Toast';
...
@@ -19,7 +19,7 @@ import Toast from 'android.widget.Toast';
import ShortcutInfoCompat from 'androidx.core.content.pm.ShortcutInfoCompat'
import ShortcutInfoCompat from 'androidx.core.content.pm.ShortcutInfoCompat'
import ShortcutManagerCompat from 'androidx.core.content.pm.ShortcutManagerCompat'
import ShortcutManagerCompat from 'androidx.core.content.pm.ShortcutManagerCompat'
import IconCompat from 'androidx.core.graphics.drawable.IconCompat'
import IconCompat from 'androidx.core.graphics.drawable.IconCompat'
import ActivityLifecycleCallbacks from 'android.app.Application.ActivityLifecycleCallbacks';
import Service from 'android.app.Service';
import Service from 'android.app.Service';
import System from 'java.lang.System';
import System from 'java.lang.System';
...
@@ -61,7 +61,64 @@ export function sayHelloFromJar(): string {
...
@@ -61,7 +61,64 @@ export function sayHelloFromJar(): string {
}
}
/**
* 调用SO动态库中的方法
*/
export function sayHelloFromSO():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 "需要在自定义基座运行";
}
let nativeLib = new NativeLib()
return nativeLib.stringFromJNI()
}
class MyLifecycleCallbacks implements ActivityLifecycleCallbacks {
override onActivityCreated(a: Activity, b: Bundle|null):void {
console.log("onActivityCreated",a)
}
override onActivityStarted(a: Activity):void {
console.log("onActivityStarted",a)
}
override onActivityResumed(a: Activity):void {
console.log("onActivityResumed",a)
}
override onActivityPaused(a: Activity):void {
console.log("onActivityPaused",a)
}
override onActivityStopped(a: Activity):void {
console.log("onActivityStopped",a)
}
override onActivitySaveInstanceState(a: Activity, b: Bundle):void {
console.log("onActivitySaveInstanceState",a)
}
override onActivityDestroyed(a: Activity):void {
console.log("onActivityDestroyed",a)
}
}
export class AppHookProxy implements UTSAndroidHookProxy {
export class AppHookProxy implements UTSAndroidHookProxy {
...
@@ -74,6 +131,9 @@ export class AppHookProxy implements UTSAndroidHookProxy {
...
@@ -74,6 +131,9 @@ export class AppHookProxy implements UTSAndroidHookProxy {
//onCreate 初始化三方SDK
//onCreate 初始化三方SDK
Log.d("AppHookProxy", "AppHookProxy--onCreate---isPrivacyAgree")
Log.d("AppHookProxy", "AppHookProxy--onCreate---isPrivacyAgree")
}
}
application.registerActivityLifecycleCallbacks(new MyLifecycleCallbacks());
}
}
}
}
...
@@ -165,7 +225,7 @@ class StartServiceListener implements OnClickListener{
...
@@ -165,7 +225,7 @@ class StartServiceListener implements OnClickListener{
override onClick(v?: View):void{
override onClick(v?: View):void{
var
intent = new Intent(UTSAndroid.getUniActivity(), ForeService().javaClass);
let
intent = new Intent(UTSAndroid.getUniActivity(), ForeService().javaClass);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
UTSAndroid.getAppContext()!.startForegroundService(intent);
UTSAndroid.getAppContext()!.startForegroundService(intent);
}
}
...
...
uni_modules/uts-nativepage/utssdk/app-android/libs/arm64-v8a/libnativelib.so
0 → 100644
浏览文件 @
6e619231
文件已添加
uni_modules/uts-nativepage/utssdk/app-android/libs/armeabi-v7a/libnativelib.so
0 → 100644
浏览文件 @
6e619231
文件已添加
uni_modules/uts-nativepage/utssdk/app-android/libs/x86/libnativelib.so
0 → 100644
浏览文件 @
6e619231
文件已添加
uni_modules/uts-nativepage/utssdk/app-android/libs/x86_64/libnativelib.so
0 → 100644
浏览文件 @
6e619231
文件已添加
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录