From d6e9787d3ee45645b1a31ffb2e538ca525d9305b Mon Sep 17 00:00:00 2001 From: duqingquan Date: Tue, 18 Oct 2022 19:59:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E9=99=A4=E5=A4=A7=E9=83=A8=E5=88=86?= =?UTF-8?q?=20uts=20=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utssdk/app-android/index.uts | 39 +++++++++++------- .../utssdk/app-android/libs/R.jar | Bin 0 -> 3547 bytes .../app-android/res/layout/demo_activity.xml | 2 +- .../utssdk/app-android/index.uts | 32 +++++++------- uni_modules/uts-syntaxcase/index.uts | 2 - .../utssdk/app-android/index.uts | 19 ++++----- 6 files changed, 51 insertions(+), 43 deletions(-) create mode 100644 uni_modules/uts-nativepage/utssdk/app-android/libs/R.jar diff --git a/uni_modules/uts-nativepage/utssdk/app-android/index.uts b/uni_modules/uts-nativepage/utssdk/app-android/index.uts index 392db82..89109f2 100644 --- a/uni_modules/uts-nativepage/utssdk/app-android/index.uts +++ b/uni_modules/uts-nativepage/utssdk/app-android/index.uts @@ -5,7 +5,6 @@ import Bundle from 'android.os.Bundle'; import R from 'io.dcloud.uni_modules.uts_nativepage.R'; import Intent from 'android.content.Intent'; import IntentFilter from 'android.content.IntentFilter'; - import NotificationCompat from 'androidx.core.app.NotificationCompat'; import NotificationManager from 'android.app.NotificationManager'; import NotificationChannel from 'android.app.NotificationChannel'; @@ -25,6 +24,8 @@ import { import Service from 'android.app.Service'; import System from 'java.lang.System'; + + class ForeService extends Service { @@ -47,14 +48,18 @@ class ForeService extends Service { let mBuilder = new NotificationCompat.Builder(this,"uts-test"); - mBuilder.setAutoCancel(true) // 点击后让通知将消失 + // 点击后让通知将消失 + mBuilder.setAutoCancel(true) mBuilder.setContentText("测试") mBuilder.setContentTitle("测试") - mBuilder.setWhen(System.currentTimeMillis()) //通知产生的时间,会在通知信息里显示 - - mBuilder.setPriority(NotificationManager.IMPORTANCE_DEFAULT) //设置该通知优先级 - mBuilder.setOngoing(false) //ture,设置他为一个正在进行的通知。他们通常是用来表示一个后台任务,用户积极参与(如播放音乐)或以某种方式正在等待,因此占用设备(如一个文件下载,同步操作,主动网络连接) - mBuilder.setDefaults(Notification.DEFAULT_ALL) //向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合: + //通知产生的时间,会在通知信息里显示 + mBuilder.setWhen(System.currentTimeMillis()) + //设置该通知优先级 + mBuilder.setPriority(NotificationManager.IMPORTANCE_DEFAULT) + //ture,设置他为一个正在进行的通知。他们通常是用来表示一个后台任务,用户积极参与(如播放音乐)或以某种方式正在等待,因此占用设备(如一个文件下载,同步操作,主动网络连接) + mBuilder.setOngoing(false) + //向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合: + mBuilder.setDefaults(Notification.DEFAULT_ALL) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @@ -72,7 +77,7 @@ class ForeService extends Service { } mBuilder.setContentIntent(null) - this.startForeground(222, mBuilder.build()) + this.startForeground(102, mBuilder.build()) return super.onStartCommand(intent, flags, startId); } @@ -87,9 +92,13 @@ class ForeService extends Service { -class ScreenReceiver extends BroadcastReceiver() { +class ScreenReceiver extends BroadcastReceiver{ - override onReceive(context: Context, intent: Intent):void { + constructor (){ + super(); + } + + override onReceive(context: Context, intent: Intent):void { if (Intent.ACTION_SCREEN_OFF == intent.action) { console.log("==屏幕休眠了") } @@ -104,7 +113,7 @@ class StartServiceListener extends OnClickListener{ override onClick(v?: View):void{ - var intent = Intent(getUniActivity(), ForeService().javaClass); + var intent = new Intent(getUniActivity(), ForeService().javaClass); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { getAppContext()!.startForegroundService(intent); } @@ -135,13 +144,15 @@ class StartBroadcastListener extends OnClickListener{ -class DemoActivity extends Activity(){ +class DemoActivity extends Activity{ + constructor (){ + super(); + } override onCreate(savedInstanceState?: Bundle):void { super.onCreate(savedInstanceState) - setContentView(R.layout.demo_activity); - + this.setContentView(R.layout.demo_activity); let btn_start_service_front = findViewById