From 6bb96332a407ff40b79a8025be78b3af806935c3 Mon Sep 17 00:00:00 2001 From: duqingquan Date: Wed, 26 Oct 2022 21:50:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=94=9F=E5=91=BD=E5=91=A8?= =?UTF-8?q?=E6=9C=9F=E7=9B=91=E5=90=AC=20=E5=A2=9E=E5=8A=A0=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/lifecycle/lifecycle.vue | 21 ++++- pages/resource/resource.vue | 15 +--- .../uts-advance/utssdk/app-android/index.uts | 79 +++++++++++++++++-- .../utssdk/app-android/index.uts | 4 +- .../uts-toast/utssdk/app-android/config.json | 7 -- .../uts-toast/utssdk/app-android/index.uts | 13 +-- 6 files changed, 103 insertions(+), 36 deletions(-) delete mode 100644 uni_modules/uts-toast/utssdk/app-android/config.json diff --git a/pages/lifecycle/lifecycle.vue b/pages/lifecycle/lifecycle.vue index 1d6a841..e0e9723 100644 --- a/pages/lifecycle/lifecycle.vue +++ b/pages/lifecycle/lifecycle.vue @@ -2,6 +2,8 @@ diff --git a/pages/resource/resource.vue b/pages/resource/resource.vue index 2ffefab..4703ffb 100644 --- a/pages/resource/resource.vue +++ b/pages/resource/resource.vue @@ -1,15 +1,13 @@ diff --git a/uni_modules/uts-advance/utssdk/app-android/index.uts b/uni_modules/uts-advance/utssdk/app-android/index.uts index 38cad64..7b0cf36 100644 --- a/uni_modules/uts-advance/utssdk/app-android/index.uts +++ b/uni_modules/uts-advance/utssdk/app-android/index.uts @@ -5,15 +5,28 @@ import ViewGroup from "android.view.ViewGroup"; import Gravity from "android.view.Gravity"; import Runnable from 'java.lang.Runnable'; import MediaPlayer from 'android.media.MediaPlayer'; +import Log from 'android.util.Log'; +import Intent from 'android.content.Intent'; import logo from "../../static/logo.png"; import PackageManager from "android.content.pm.PackageManager"; +import MediaStore from "android.provider.MediaStore"; +import Bundle from "android.os.Bundle"; +import ActivityCompat from "androidx.core.app.ActivityCompat"; +import Manifest from "android.Manifest"; +import Activity from "android.app.Activity"; +import Bitmap from "android.graphics.Bitmap"; +import FileOutputStream from "java.io.FileOutputStream"; import { onAppActivityDestroy, onAppActivityPause, onAppActivityResume, onAppActivityBack, + onAppActivityStop, + onAppActivityResult, + onAppTrimMemory, + onAppConfigChange, getUniActivity, getAppContext } from "io.dcloud.uts.android"; @@ -179,7 +192,44 @@ export function playAssetAudio() { } - +export function goOtherActivity(imageDone: (event:string) => void):boolean { + + // 检查相关权限是否已经具备 + if (ActivityCompat.checkSelfPermission(getUniActivity()!, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { + // 不具备权限,申请权限,并且告知用户监听失败 + ActivityCompat.requestPermissions(getUniActivity()!, arrayOf(Manifest.permission.CAMERA), 1002) + + return false; + } + + onAppActivityResult((requestCode: Int, resultCode: Int, data?: Intent) => { + let eventName = "onAppActivityResult - requestCode:" + requestCode + " -resultCode:"+resultCode + " -data:"+JSON.stringify(data); + console.log(eventName); + if ((requestCode == 1001) && (resultCode == Activity.RESULT_OK)) { + if (data != null) { + let bundle = data.getExtras(); + let mImageBitmap = bundle!.get("data") as Bitmap; + let bitmapPath = getUniActivity()!.getExternalCacheDir()!.getPath() + "/photo.png" + console.log(bitmapPath); + try{ + mImageBitmap.compress(Bitmap.CompressFormat.PNG,100,new FileOutputStream(bitmapPath)) + }catch(e){ + } + imageDone(bitmapPath); + + } + } + }); + + let takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + //resolveActivity 返回可处理 Intent 的第一个 Activity 组件 + if (takePictureIntent.resolveActivity(getUniActivity()!.getPackageManager()) != null) { + getUniActivity()!.startActivityForResult(takePictureIntent, 1001); + } + + return true; + +} /** @@ -188,21 +238,40 @@ export function playAssetAudio() { */ export function initAppLifecycle(onLifecycleChange: (event:string) => void) { + + + onAppTrimMemory((level:Number) => { + let eventName = "onAppTrimMemory - " + level; + onLifecycleChange(eventName); + console.log(eventName); + }); + + + onAppConfigChange((ret:UTSJSONObject) => { + let eventName = "onAppConfigChange - " + JSON.stringify(ret); + onLifecycleChange(eventName); + console.log(eventName); + }); + + /** * activity 销毁生命周期回调 * 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivitydestroy */ onAppActivityDestroy(() => { - let eventName = "onAppActivityDestroy - " + Date.now(); + let eventName = "onAppActivityDestroy"; onLifecycleChange(eventName); console.log(eventName); }); + + + /** * activity 失去焦点生命周期回调 * 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivitypause */ onAppActivityPause(() => { - let eventName = "onAppActivityPause - " + Date.now(); + let eventName = "onAppActivityPause" ; onLifecycleChange(eventName); console.log(eventName); }); @@ -211,7 +280,7 @@ export function initAppLifecycle(onLifecycleChange: (event:string) => void) { * 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivityresume */ onAppActivityResume(() => { - let eventName = "onAppActivityResume - " + Date.now(); + let eventName = "onAppActivityResume"; onLifecycleChange(eventName); console.log(eventName); }); @@ -220,7 +289,7 @@ export function initAppLifecycle(onLifecycleChange: (event:string) => void) { * 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivityback */ onAppActivityBack(() => { - let eventName = "onAppActivityBack - " + Date.now(); + let eventName = "onAppActivityBack"; onLifecycleChange(eventName); console.log(eventName); }); diff --git a/uni_modules/uts-nativepage/utssdk/app-android/index.uts b/uni_modules/uts-nativepage/utssdk/app-android/index.uts index 89109f2..c9e2bdc 100644 --- a/uni_modules/uts-nativepage/utssdk/app-android/index.uts +++ b/uni_modules/uts-nativepage/utssdk/app-android/index.uts @@ -40,7 +40,7 @@ class ForeService extends Service { } - override onBind(intent?: Intent): IBinder|null{ + override onBind(_intent?: Intent): IBinder|null{ return null; } @@ -98,7 +98,7 @@ class ScreenReceiver extends BroadcastReceiver{ super(); } - override onReceive(context: Context, intent: Intent):void { + override onReceive(_context: Context, intent: Intent):void { if (Intent.ACTION_SCREEN_OFF == intent.action) { console.log("==屏幕休眠了") } diff --git a/uni_modules/uts-toast/utssdk/app-android/config.json b/uni_modules/uts-toast/utssdk/app-android/config.json deleted file mode 100644 index 68231cf..0000000 --- a/uni_modules/uts-toast/utssdk/app-android/config.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "abis": [ - "arm64-v8a" - ], - "minSdkVersion": 21 -} - diff --git a/uni_modules/uts-toast/utssdk/app-android/index.uts b/uni_modules/uts-toast/utssdk/app-android/index.uts index 472deed..26c44ff 100644 --- a/uni_modules/uts-toast/utssdk/app-android/index.uts +++ b/uni_modules/uts-toast/utssdk/app-android/index.uts @@ -5,21 +5,14 @@ import { import XToast from "com.hjq.xtoast.XToast"; import R from "io.dcloud.uni_modules.uts_toast.R"; -export function getLogoPath():string{ +export function showToast():string{ - // new XToast(getUniActivity()) - // .setDuration(1000) - // .setContentView(R.layout.window_hint) - // .setImageDrawable(android.R.id.icon, android.R.mipmap.sym_def_app_icon) - // .setText(android.R.id.message, "一秒后自动消失") - // .show(); - - XToast>(getUniActivity()) + new XToast>(getUniActivity()) .setDuration(1000) .setContentView(R.layout.window_hint) .setImageDrawable(android.R.id.icon, android.R.mipmap.sym_def_app_icon) .setText(android.R.id.message, "一秒后自动消失") .show() - return "hello toast" + return "" } \ No newline at end of file -- GitLab