|
|
3 mēneši atpakaļ | |
|---|---|---|
| .. | ||
| utssdk | 3 mēneši atpakaļ | |
| changelog.md | 3 mēneši atpakaļ | |
| encrypt | 3 mēneši atpakaļ | |
| package.json | 3 mēneši atpakaļ | |
| readme.md | 3 mēneši atpakaļ | |
长期维护,有任何问题请在插件群联系作者
1.android/iOS端需要自定义基座
2.ios 端若觉得效果不佳,可以解压ios 插件目录下的uni_modules\android-keeplive\utssdk\app-ios\info.zip 将info.plist 文件和uts 文件在同一个级别 文件(上架可能会困难一点)
3.推荐android端合井使用作者一像素保活效果更佳链接
1.最近任务给程序加锁,2.在系统设置启动项开启应用程序后台运行
选择试用,绑定要试用的项目appid,
选择后下载到对应的本地项目,
按照文档 -》把插件引入项目(即 import { KeepLive } from '@/uni_modules/android-keeplive' 需要先引入),
发布-》云打包-》选择制作基座-》打包等基座制作完成
运行 -》 运行到手机或模拟器-》运行到Androidapp基座-》选择使用自定义基座运行-》选择手机-》运行
若之前手机安装过基座需要先卸载之前的基座
// #ifdef APP
import { KeepLive } from '@/uni_modules/android-keeplive' // 放在页面导入的地方
// #endif
//<!-- ------------------------------下方代码需要放进方法中-------------------------------------------------- -->
// #ifdef APP
var keep=new KeepLive();
keep.setTitle("app");
keep.setContent("app is runing");
// keep.setLargeIcon("icon");
keep.setSmallIcon("icon"); //图标名字 图标放在 插件下面的 uni_modules\android-keeplive\utssdk\app-android\res 文件夹下
keep.onAddBackgroundCallback(function(res:boolean){
console.log("后台运行 "+res)
})
keep.onAddScrrenListenerCallback(function(res:boolean){
console.log("屏幕开启状态 "+res)
})
keep.onAddNotificationClickListener(function(d:string){
// d 为点击通知栏信息 的json字符
console.log(d);
})
keep.setWakeLock(1,"keeptag");// 设置唤醒类型
keep.setAutoStartEnable(true)
if(!keep.checkAppNotification()){
keep.onOpenNotificationSetting(function(res:boolean){
keep.register();
var ignoring= keep.isIgnoringBatteryOptimizations();
if(!ignoring){
keep.requestIgnoreBatteryOptimizations();
}
})
}else{
keep.register();
var ignoring= keep.isIgnoringBatteryOptimizations();
if(!ignoring){
keep.requestIgnoreBatteryOptimizations();
}
}
// 稳定定时器 需要的用户使用(默认定时器1 )
keep.onStartCSystemTimer(60,function(){
console.log("onStartCSystemTimer ");
keep.acquire(1000);// 唤醒一秒钟
});
// 需要插件增加程序后台运行能力的可以加下面代码 想程序始终保持活性(即稳定推送 scocket等)(体验好) 还是建议用户打开系统设置 启动项 后台运行
//keep.wifilock();//部分手机可能会断
// 定时器时间改成10秒 去掉上方的
//keep.onStartCSystemTimer(10,function(){
// console.log("onStartCSystemTimer ");
// keep.acquire(1000);// 唤醒一秒钟
//});
// #endif
// #ifdef APP
import { KeepLive } from '@/uni_modules/android-keeplive' // 放在页面导入的地方
// #endif
//<!-- ------------------------------下方代码需要放进方法中-------------------------------------------------- -->
// #ifdef APP
var keep=new KeepLive();
keep.setTitle("app");
keep.setContent("app is runing");
// keep.setLargeIcon("icon");
keep.setSmallIcon("icon"); //图标名字 图标放在 插件下面的 res/drawable 文件夹下
keep.onAddBackgroundCallback(function(res){
console.log("后台运行 "+res)
})
keep.onAddScrrenListenerCallback(function(res){
console.log("屏幕开启状态 "+res)
})
keep.onAddNotificationClickListener(function(d){
// d 为点击通知栏信息 的json字符
console.log(d);
})
keep.setWakeLock(1,"keeptag");// 设置唤醒类型
keep.setAutoStartEnable(true)
if(!keep.checkAppNotification()){
keep.onOpenNotificationSetting(function(res){
keep.register();
var ignoring= keep.isIgnoringBatteryOptimizations();
if(!ignoring){
keep.requestIgnoreBatteryOptimizations();
}
})
}else{
keep.register();
var ignoring= keep.isIgnoringBatteryOptimizations();
if(!ignoring){
keep.requestIgnoreBatteryOptimizations();
}
}
keep.onStartCSystemTimer(60,function(){
console.log("onStartCSystemTimer ");
keep.acquire(1000);// 唤醒一秒钟
});
// 需要插件增加程序后台运行能力的可以加下面代码 想程序始终保持活性(即稳定推送 scocket等)(体验好) 还是建议用户打开系统设置 启动项 后台运行
//keep.wifilock();//部分手机可能会断
// 定时器时间改成3秒 去掉上方的
//keep.onStartCSystemTimer(3,function(){
// console.log("onStartCSystemTimer ");
// keep.acquire(1000);// 唤醒一秒钟
//});
// #endif
安卓腾讯定位(后续支持ios)
// #ifdef APP
import { isProviderEnabled, openLocSetting, onStartLocs,LocData,stop,LocationData} from "@/uni_modules/xtf-gpslocation"
// #endif
// #ifdef APP
// 停用后台播放音乐
keep.setBackgroundMusicEnabled(false);
// 后台定位则需要使用插件的定时器 息屏也能执行,自定定时器易休眠停止执行
// 先启动定位
var on=isProviderEnabled();// 是否开启gps
if(on){
keep.onStartCSystemTimer(60,function(){
onStartLocs({
backgroud:true,
} as LocData,function(data:LocationData){
console.log(data)
})
});
}
// #endif
import { isProviderEnabled, openLocSetting, onStartLocs,LocData,stop} from "@/uni_modules/xtf-gpslocation"
// 停用后台播放音乐
keep.setBackgroundMusicEnabled(false);
// 后台定位则需要使用插件的定时器 息屏也能执行,自定定时器易休眠停止执行
// 先启动定位
var on=isProviderEnabled();// 是否开启gps
if(on){
keep.onStartCSystemTimer(60,function(){
onStartLocs({
backgroud:true,
} ,function(res){
console.log(res)
})
});
}
keep.register();
keep.restart();
keep.unregister();
return boolean
var run=keep.isRunning();
var on=keep.checkAppNotification();
keep.goNotificationSetting();
uniappx
keep.onOpenNotificationSetting(function(on:boolean){
})
uniapp
keep.onOpenNotificationSetting(function(on){
})
参数1 应用包名 string
keep.doStartApplicationWithPackageName("com.test");
keep.requestIgnoreBatteryOptimizations();
return boolean
var ignoring= keep.isIgnoringBatteryOptimizations();
参数1 boolean
keep.setBackgroundMusicEnabled(true);
uniappx
keep.onAddNotificationClickListener(function(d:string){
// d 为点击通知栏信息 的json字符
console.log(d);
})
uniapp
keep.onAddNotificationClickListener(function(d){
// d 为点击通知栏信息 的json字符
console.log(d);
})
参数1 boolean
keep.hideNotification(false);
参数1 boolean
keep.setNotifaicationSoundEnable(true);
keep.setNotifationId(333);// id 为随意 重复为更新通知 不同为发布新的
参数1 string
keep.setChannelId("keeplive");
keep.setTitle("Test");
keep.setContent("test runing");
keep.updateNotification();
参数1 string
keep.setTitle("title");
参数1 string
keep.setContent("msg");
参数1 number 1-3 低到高
keep.setChannelImportance(3);
keep.setLockscreenVisibility(1); 锁屏可见性,可选范围VISIBILITY_PRIVATE:0、VISIBILITY_PUBLIC:1、VISIBILITY_SECRET:-1、VISIBILITY_NO_OVERRIDE:-1000
keep.enableVibration(true);// true 开启 false 关闭
keep.setNotifationMsgGroup("test");// 设置后更新通知 通知在一个分组 通知 setNotifationId需要不同
keep.setNotifationExterData("data");
this.id=this.id+1;
keep.setTitle("Test"+this.id);
keep.setContent("test runing");
keep.setNotifationExterData("xxxaa22233"+this.id);
keep.setNotifationMsgGroup("test");
keep.updateNotification();
参数1 string 插件的res drawable 目录下 名称
keep.setSmallIcon("icon");
参数1 string 插件的res drawable 目录下 名称
keep.setLargeIcon("icon");
keep.setAutoCancel(false);// false 表示不可取消 true 表示可取消
keep.cancelGroupNotifaon("test")
keep.cancelNotifation(0)
参数1 number
1:保持CPU 运转,屏幕和键盘灯有可能是关闭的。
参数2 string tag
keep.setWakeLock(1,"tag");
参数1 number 时间
keep.acquire(-1);
keep.releaseAcquire();
keep.setMusicVol(0) // 0~1 范围
keep.setMusicId("music") // 将音乐放进 插件目录 /res/raw/music.mp3
keep.toBackground();
//开启定时器 60时间为秒
keep.onStartCSystemTimer(60,function(){
console.log("onStartCSystemTimer ")
});
//keep.cancelCSystemTimer();// 取消定时器
//keep.clearAllCTimer(); // 取消全部定时器
// android 原生定时任何状态一秒误差, 开始时间 1000为1秒0是马上执行, 开启周期 65*1000, 循环时间 大于60s 精准有效 低于60秒偏差误差
keep.startAleraTask(0,65*1000,function(){
console.log("onAleraTaskListener ")
});
//取消循环定时
keep.cancleAleraTask()
var liveTime=keep.getLiveTime();// 毫秒时间
参数1 boolean true 为隐藏,false为显示
keep.hideRecentTask(true);// 隐藏
keep.goAndroidSystemAppSetting();
keep.setCrashRestartUIEnabled(true);
android channel 为android通知栏通配置
对使用插件app的新用户
本插件的channelId 默认为keeplive channelName 默认为keeplive 默认为有声通知。首次调用keep.register()/keep.updateNotification() 这个channel 就会自定创建好,并且不可修改
本插件可自定义channel 在调用keep.register()/keep.updateNotification()之前调用下面代码
keep.setNotifaicationSoundEnable(false);
keep.setChannelId("保活");
keep.setChannelName("保活") //通知名称
keep.register();//keep.updateNotification()/* 同样为调用即为创建,之后不可修改,但是可以添加新的, 调用其中一个即可,之后就一直按照新的配置发送通知*/
keep.wifilock();// 休眠时锁定wifi
keep.wifiunlock();// 休眠时取消锁定wifi