Intent intent = new Intent("com.example.fingureprint.services.JudgeFingureService");
intent.setPackage(getPackageName());
startService(intent);
<!--注册判断指纹密码开启的服务-->
<service
android:name="com.example.fingureprint.services.JudgeFingureService"
android:enabled="true">
<intent-filter >
<action android:name="com.example.fingureprint.services.JudgeFingureService"/>
</intent-filter>
</service>
new Thread(){
public void run() {
try {
while(true){
Thread.sleep(1000);
if(isAppOnForeground()){
Log.i("前台运行", "time"+countnumber);
if(countnumber>30){
if(!"com.example.fingureprint.FingureAriseActivity".equals(listActivity())){
Intent myintent = new Intent();
myintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
myintent.setClass(getApplicationContext(),FingureAriseActivity.class);
startActivity(myintent);
}
countnumber = 0;
}else{
countnumber = 0;
}
}else{
Log.i("后台运行", "time"+countnumber);
countnumber ++;
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
};
}.start();
/**
* 判断程序在前台运行的方法
* @return
*/
public boolean isAppOnForeground() {
ActivityManager systemService = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> runningAppProcesses = systemService.getRunningAppProcesses();
if(runningAppProcesses==null) return false;
for(RunningAppProcessInfo processes: runningAppProcesses){
if(processes.processName.equals("com.example.fingureprint")&&processes.importance==RunningAppProcessInfo.IMPORTANCE_FOREGROUND){
return true;
}
}
return false;
}
/**
* 判断当前运行在前台的Activity
*/
@SuppressWarnings("deprecation")
public String listActivity(){
ActivityManager systemService = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> runningTasks = systemService.getRunningTasks(1);
RunningTaskInfo runningTaskInfo = runningTasks.get(0);
ComponentName component = runningTaskInfo.topActivity;
String className = component.getClassName();
return className;
}
<uses-permission android:name="android.permission.USE_FINGERPRINT"/>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有