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

消除大部分 uts 警告

上级 595ffcd2
...@@ -5,7 +5,6 @@ import Bundle from 'android.os.Bundle'; ...@@ -5,7 +5,6 @@ import Bundle from 'android.os.Bundle';
import R from 'io.dcloud.uni_modules.uts_nativepage.R'; import R from 'io.dcloud.uni_modules.uts_nativepage.R';
import Intent from 'android.content.Intent'; import Intent from 'android.content.Intent';
import IntentFilter from 'android.content.IntentFilter'; import IntentFilter from 'android.content.IntentFilter';
import NotificationCompat from 'androidx.core.app.NotificationCompat'; import NotificationCompat from 'androidx.core.app.NotificationCompat';
import NotificationManager from 'android.app.NotificationManager'; import NotificationManager from 'android.app.NotificationManager';
import NotificationChannel from 'android.app.NotificationChannel'; import NotificationChannel from 'android.app.NotificationChannel';
...@@ -25,6 +24,8 @@ import { ...@@ -25,6 +24,8 @@ import {
import Service from 'android.app.Service'; import Service from 'android.app.Service';
import System from 'java.lang.System'; import System from 'java.lang.System';
class ForeService extends Service { class ForeService extends Service {
...@@ -47,14 +48,18 @@ class ForeService extends Service { ...@@ -47,14 +48,18 @@ class ForeService extends Service {
let mBuilder = new NotificationCompat.Builder(this,"uts-test"); let mBuilder = new NotificationCompat.Builder(this,"uts-test");
mBuilder.setAutoCancel(true) // 点击后让通知将消失 // 点击后让通知将消失
mBuilder.setAutoCancel(true)
mBuilder.setContentText("测试") mBuilder.setContentText("测试")
mBuilder.setContentTitle("测试") mBuilder.setContentTitle("测试")
mBuilder.setWhen(System.currentTimeMillis()) //通知产生的时间,会在通知信息里显示 //通知产生的时间,会在通知信息里显示
mBuilder.setWhen(System.currentTimeMillis())
mBuilder.setPriority(NotificationManager.IMPORTANCE_DEFAULT) //设置该通知优先级 //设置该通知优先级
mBuilder.setOngoing(false) //ture,设置他为一个正在进行的通知。他们通常是用来表示一个后台任务,用户积极参与(如播放音乐)或以某种方式正在等待,因此占用设备(如一个文件下载,同步操作,主动网络连接) mBuilder.setPriority(NotificationManager.IMPORTANCE_DEFAULT)
mBuilder.setDefaults(Notification.DEFAULT_ALL) //向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合: //ture,设置他为一个正在进行的通知。他们通常是用来表示一个后台任务,用户积极参与(如播放音乐)或以某种方式正在等待,因此占用设备(如一个文件下载,同步操作,主动网络连接)
mBuilder.setOngoing(false)
//向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合:
mBuilder.setDefaults(Notification.DEFAULT_ALL)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
...@@ -72,7 +77,7 @@ class ForeService extends Service { ...@@ -72,7 +77,7 @@ class ForeService extends Service {
} }
mBuilder.setContentIntent(null) mBuilder.setContentIntent(null)
this.startForeground(222, mBuilder.build()) this.startForeground(102, mBuilder.build())
return super.onStartCommand(intent, flags, startId); return super.onStartCommand(intent, flags, startId);
} }
...@@ -87,7 +92,11 @@ class ForeService extends Service { ...@@ -87,7 +92,11 @@ class ForeService extends Service {
class ScreenReceiver extends BroadcastReceiver() { class ScreenReceiver extends BroadcastReceiver{
constructor (){
super();
}
override onReceive(context: Context, intent: Intent):void { override onReceive(context: Context, intent: Intent):void {
if (Intent.ACTION_SCREEN_OFF == intent.action) { if (Intent.ACTION_SCREEN_OFF == intent.action) {
...@@ -104,7 +113,7 @@ class StartServiceListener extends OnClickListener{ ...@@ -104,7 +113,7 @@ class StartServiceListener extends OnClickListener{
override onClick(v?: View):void{ 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) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
getAppContext()!.startForegroundService(intent); getAppContext()!.startForegroundService(intent);
} }
...@@ -135,13 +144,15 @@ class StartBroadcastListener extends OnClickListener{ ...@@ -135,13 +144,15 @@ class StartBroadcastListener extends OnClickListener{
class DemoActivity extends Activity(){ class DemoActivity extends Activity{
constructor (){
super();
}
override onCreate(savedInstanceState?: Bundle):void { override onCreate(savedInstanceState?: Bundle):void {
super.onCreate(savedInstanceState) 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); let btn_start_service_front = findViewById<Button>(R.id.btn_start_service_front);
btn_start_service_front.setOnClickListener(new StartServiceListener()); btn_start_service_front.setOnClickListener(new StartServiceListener());
......
...@@ -6,5 +6,5 @@ ...@@ -6,5 +6,5 @@
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="demo text"/> <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_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> </LinearLayout>
\ No newline at end of file
...@@ -12,6 +12,7 @@ import Build from "android.os.Build"; ...@@ -12,6 +12,7 @@ import Build from "android.os.Build";
import FileObserver from "android.os.FileObserver"; import FileObserver from "android.os.FileObserver";
import File from "java.io.File"; import File from "java.io.File";
import Environment from "android.os.Environment"; import Environment from "android.os.Environment";
import System from 'java.lang.System';
...@@ -24,15 +25,10 @@ let screenOB: ScreenFileObserver | null = null; ...@@ -24,15 +25,10 @@ let screenOB: ScreenFileObserver | null = null;
*/ */
let lastFileObserverTime: number = 0; let lastFileObserverTime: number = 0;
/** /**
* 图片捕捉定义 * 图片被捕获的实现
*/ */
type OnImageCatchOptions = { let imageChange: UTSCallback | null = null;
onImageCatchChange: (res: any) => void;
};
/**
* 图片捕捉监听变量
*/
let listenOption = new OnImageCatchOptions();
...@@ -54,12 +50,12 @@ class ScreenFileObserver extends FileObserver { ...@@ -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) { 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(); let currentTime = System.currentTimeMillis();
if ((currentTime - lastFileObserverTime) < 1000) { if ((currentTime - lastFileObserverTime) < 1000) {
...@@ -71,7 +67,8 @@ class ScreenFileObserver extends FileObserver { ...@@ -71,7 +67,8 @@ class ScreenFileObserver extends FileObserver {
let ret = { let ret = {
image:newPath image:newPath
} }
listenOption.onImageCatchChange(ret)
imageChange!(ret);
} }
} }
} }
...@@ -99,20 +96,22 @@ export function requestPremission() { ...@@ -99,20 +96,22 @@ export function requestPremission() {
/** /**
* 开启截图监听 * 开启截图监听
*/ */
export function onUserCaptureScreen(success: (res: any) => void) { export function onUserCaptureScreen(callback: (res:UTSJSONObject) => void) {
listenOption.onImageCatchChange = success;
// android 10 以上版本,使用监听文件的方式,更加可靠 imageChange = callback;
let directory_screenshot: File;
let directory_screenshot: File;
// 找到设备存放截屏文件的目录
let directory_pictures = new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_PICTURES); let directory_pictures = new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_PICTURES);
let directory_dcim = new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DCIM); 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"); directory_screenshot = new File(directory_dcim, "Screenshots");
} else { } else {
directory_screenshot = new File(directory_pictures, "Screenshots"); directory_screenshot = new File(directory_pictures, "Screenshots");
...@@ -121,6 +120,7 @@ export function onUserCaptureScreen(success: (res: any) => void) { ...@@ -121,6 +120,7 @@ export function onUserCaptureScreen(success: (res: any) => void) {
if (screenOB != null) { if (screenOB != null) {
screenOB!.stopWatching() screenOB!.stopWatching()
} }
//开始监听
screenOB = new ScreenFileObserver(directory_screenshot.path) screenOB = new ScreenFileObserver(directory_screenshot.path)
screenOB!.startWatching() screenOB!.startWatching()
......
import { log } from "./utils.uts";
type AsyncOptions = { type AsyncOptions = {
type: string; type: string;
success: (res: string) => void; success: (res: string) => void;
...@@ -16,7 +15,6 @@ export const MAX = 100; ...@@ -16,7 +15,6 @@ export const MAX = 100;
*/ */
export function testSync(msg: string) { export function testSync(msg: string) {
console.log("log test"); console.log("log test");
log("log test1");
return { return {
msg: `hello ${msg}`, msg: `hello ${msg}`,
}; };
......
import { import {
onAppActivityPause,
onAppActivityRequestPermissionsResult, onAppActivityRequestPermissionsResult,
getUniActivity, getUniActivity,
getAppContext getAppContext
...@@ -76,21 +75,21 @@ class LocationOptionsWapper{ ...@@ -76,21 +75,21 @@ class LocationOptionsWapper{
this.hostOption = option this.hostOption = option
} }
onLocationChanged(location:TencentLocation , error:Int , onLocationChanged(location:TencentLocation , _error:Int ,
reason:string){ _reason:string){
let response = new LocationResponse(); let response = {
response.name = location.name; name:location.name,
response.address = location.address; address:location.address,
response.latitude = location.latitude; latitude:location.latitude,
response.longitude = location.longitude; longitude:location.longitude
};
this.hostOption.success(response); 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.
先完成此消息的编辑!
想要评论请 注册