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

消除大部分 uts 警告

上级 595ffcd2
......@@ -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<Button>(R.id.btn_start_service_front);
btn_start_service_front.setOnClickListener(new StartServiceListener());
......
......@@ -6,5 +6,5 @@
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="demo text"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="开启前台服务(应用包活)" android:id="@+id/btn_start_service_front"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="注册网络状态广播监听" android:id="@+id/btn_start_screen_listen"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="注册屏幕状态广播监听" android:id="@+id/btn_start_screen_listen"/>
</LinearLayout>
\ No newline at end of file
......@@ -12,6 +12,7 @@ import Build from "android.os.Build";
import FileObserver from "android.os.FileObserver";
import File from "java.io.File";
import Environment from "android.os.Environment";
import System from 'java.lang.System';
......@@ -24,15 +25,10 @@ let screenOB: ScreenFileObserver | null = null;
*/
let lastFileObserverTime: number = 0;
/**
* 图片捕捉定义
* 图片被捕获的实现
*/
type OnImageCatchOptions = {
onImageCatchChange: (res: any) => void;
};
/**
* 图片捕捉监听变量
*/
let listenOption = new OnImageCatchOptions();
let imageChange: UTSCallback | null = null;
......@@ -54,12 +50,12 @@ class ScreenFileObserver extends FileObserver {
}
override onEvent(event: Int, path?: String): void {
override onEvent(event: Int, path?: string): void {
// 只监听文件新增事件
if (event == FileObserver.CREATE) {
let newPath: string = new File(this.allScreen, path!).path;
let newPath: string = new File(this.allScreen, path!).getPath();
let currentTime = System.currentTimeMillis();
if ((currentTime - lastFileObserverTime) < 1000) {
......@@ -71,7 +67,8 @@ class ScreenFileObserver extends FileObserver {
let ret = {
image:newPath
}
listenOption.onImageCatchChange(ret)
imageChange!(ret);
}
}
}
......@@ -99,20 +96,22 @@ export function requestPremission() {
/**
* 开启截图监听
*/
export function onUserCaptureScreen(success: (res: any) => void) {
export function onUserCaptureScreen(callback: (res:UTSJSONObject) => void) {
listenOption.onImageCatchChange = success;
imageChange = callback;
// android 10 以上版本,使用监听文件的方式,更加可靠
let directory_screenshot: File;
// 找到设备存放截屏文件的目录
let directory_pictures = new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_PICTURES);
let directory_dcim = new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DCIM);
if (Build.MANUFACTURER.equals("Xiaomi", true)) {
if (Build.MANUFACTURER.lowercase() === "xiaomi") {
directory_screenshot = new File(directory_dcim, "Screenshots");
} else {
directory_screenshot = new File(directory_pictures, "Screenshots");
......@@ -121,6 +120,7 @@ export function onUserCaptureScreen(success: (res: any) => void) {
if (screenOB != null) {
screenOB!.stopWatching()
}
//开始监听
screenOB = new ScreenFileObserver(directory_screenshot.path)
screenOB!.startWatching()
......
import { log } from "./utils.uts";
type AsyncOptions = {
type: string;
success: (res: string) => void;
......@@ -16,7 +15,6 @@ export const MAX = 100;
*/
export function testSync(msg: string) {
console.log("log test");
log("log test1");
return {
msg: `hello ${msg}`,
};
......
import {
onAppActivityPause,
onAppActivityRequestPermissionsResult,
getUniActivity,
getAppContext
......@@ -76,21 +75,21 @@ class LocationOptionsWapper{
this.hostOption = option
}
onLocationChanged(location:TencentLocation , error:Int ,
reason:string){
onLocationChanged(location:TencentLocation , _error:Int ,
_reason:string){
let response = new LocationResponse();
response.name = location.name;
response.address = location.address;
response.latitude = location.latitude;
response.longitude = location.longitude;
let response = {
name:location.name,
address:location.address,
latitude:location.latitude,
longitude:location.longitude
};
this.hostOption.success(response);
}
onStatusUpdate(name:string, status:Int, desc:string){
onStatusUpdate(_name:string, _status:Int, _desc:string){
// 定位状态发生变化
//hostOption.onStatusUpdate(name,status,desc);
}
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册