update:2021.01.29
fix:锁屏界面修改为全屏,屏蔽导航栏和通知栏 add:
This commit is contained in:
@@ -112,6 +112,7 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
|
compileOnly files('src/main/libs/classes.jar')
|
||||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||||
//implementation 'com.android.support:multidex:1.0.3'
|
//implementation 'com.android.support:multidex:1.0.3'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||||
|
|||||||
@@ -11,10 +11,11 @@
|
|||||||
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
|
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
|
||||||
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
|
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
|
||||||
<uses-permission android:name="android.permission.MASTER_CLEAR" />
|
<uses-permission android:name="android.permission.MASTER_CLEAR" />
|
||||||
<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE" /> <!-- 系统权限,有系统签名可以使用 -->
|
<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE" />
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH"/>
|
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
|
<!-- 系统权限,有系统签名可以使用 -->
|
||||||
<!-- Required -->
|
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||||
|
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <!-- Required -->
|
||||||
<permission
|
<permission
|
||||||
android:name="com.info.sn.permission.JPUSH_MESSAGE"
|
android:name="com.info.sn.permission.JPUSH_MESSAGE"
|
||||||
android:protectionLevel="signature" /> <!-- Required 一些系统要求的权限,如访问网络等 -->
|
android:protectionLevel="signature" /> <!-- Required 一些系统要求的权限,如访问网络等 -->
|
||||||
@@ -56,6 +57,16 @@
|
|||||||
android:roundIcon="@mipmap/ic_launcher"
|
android:roundIcon="@mipmap/ic_launcher"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
|
<service
|
||||||
|
android:name=".service.ScreenLockService"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter android:priority="1000">
|
||||||
|
<action android:name="android.intent.action.USER_PRESENT" />
|
||||||
|
<action android:name="android.intent.action.SCREEN_ON" />
|
||||||
|
<action android:name="android.intent.action.SCREEN_OFF" />
|
||||||
|
</intent-filter>
|
||||||
|
</service>
|
||||||
<service
|
<service
|
||||||
android:name=".service.InitJpushServer"
|
android:name=".service.InitJpushServer"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
@@ -69,7 +80,8 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<activity android:name=".activity.MainActivity"
|
<activity
|
||||||
|
android:name=".activity.MainActivity"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
android:screenOrientation="sensor">
|
android:screenOrientation="sensor">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
@@ -207,7 +219,14 @@
|
|||||||
<category android:name="com.info.sn" />
|
<category android:name="com.info.sn" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".activity.TopActivity" /> <!-- Since JCore2.0.0 Required SDK核心功能 -->
|
<activity
|
||||||
|
android:name=".activity.ScreenLockActivity"
|
||||||
|
android:taskAffinity=".activity.ScreenLockActivity">
|
||||||
|
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Since JCore2.0.0 Required SDK核心功能 -->
|
||||||
<!-- 这个Service要继承JCommonService -->
|
<!-- 这个Service要继承JCommonService -->
|
||||||
<service
|
<service
|
||||||
android:name=".jpush.PushService"
|
android:name=".jpush.PushService"
|
||||||
@@ -220,7 +239,7 @@
|
|||||||
<service android:name=".service.MyDownloadService" />
|
<service android:name=".service.MyDownloadService" />
|
||||||
<service android:name=".service.StepService" /> <!-- User defined. For test only 用户自定义的广播接收器 -->
|
<service android:name=".service.StepService" /> <!-- User defined. For test only 用户自定义的广播接收器 -->
|
||||||
<receiver
|
<receiver
|
||||||
android:name="com.info.sn.jpush.MyReceiver"
|
android:name=".jpush.MyReceiver"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="false">
|
android:exported="false">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
@@ -242,15 +261,13 @@
|
|||||||
<receiver
|
<receiver
|
||||||
android:name=".receiver.InstallResultReceiver"
|
android:name=".receiver.InstallResultReceiver"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="true" />
|
android:exported="true" /> <!-- Required . Enable it you can get statistics data with channel -->
|
||||||
<!-- Required . Enable it you can get statistics data with channel -->
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="JPUSH_CHANNEL"
|
android:name="JPUSH_CHANNEL"
|
||||||
android:value="developer-default" />
|
android:value="developer-default" />
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="JPUSH_APPKEY"
|
android:name="JPUSH_APPKEY"
|
||||||
android:value="edf9cec22731b8b2fed56ee6" />
|
android:value="edf9cec22731b8b2fed56ee6" /> <!-- 设置key -->
|
||||||
<!-- 设置key -->
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="com.amap.api.v2.apikey"
|
android:name="com.amap.api.v2.apikey"
|
||||||
android:value="83869aed8624eb00615c2b6d3d15d777" />
|
android:value="83869aed8624eb00615c2b6d3d15d777" />
|
||||||
|
|||||||
@@ -3,18 +3,22 @@ package com.info.sn.activity;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import com.info.sn.R;
|
import com.info.sn.R;
|
||||||
|
|
||||||
|
|
||||||
public class TopActivity extends AppCompatActivity {
|
public class ScreenLockActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_top);
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
|
||||||
|
setContentView(R.layout.activity_screen_lock);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -30,4 +34,9 @@ public class TopActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
return super.onKeyDown(keyCode, event);
|
return super.onKeyDown(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ import android.util.Log;
|
|||||||
import com.info.sn.service.GuardService;
|
import com.info.sn.service.GuardService;
|
||||||
import com.info.sn.service.InitJpushServer;
|
import com.info.sn.service.InitJpushServer;
|
||||||
import com.info.sn.service.MyDownloadService;
|
import com.info.sn.service.MyDownloadService;
|
||||||
|
import com.info.sn.service.ScreenLockService;
|
||||||
import com.info.sn.service.StepService;
|
import com.info.sn.service.StepService;
|
||||||
|
|
||||||
|
|
||||||
@@ -35,6 +36,8 @@ public class BootReceiver extends BroadcastReceiver {
|
|||||||
context.startService(new Intent(context, StepService.class));
|
context.startService(new Intent(context, StepService.class));
|
||||||
context.startService(new Intent(context, InitJpushServer.class));
|
context.startService(new Intent(context, InitJpushServer.class));
|
||||||
context.startService(new Intent(context, MyDownloadService.class));
|
context.startService(new Intent(context, MyDownloadService.class));
|
||||||
|
context.startService(new Intent(context, ScreenLockService.class));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import android.util.DisplayMetrics;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@@ -27,8 +28,7 @@ import com.info.sn.bean.BaseResponse;
|
|||||||
import com.info.sn.network.HTTPInterface;
|
import com.info.sn.network.HTTPInterface;
|
||||||
import com.info.sn.network.NetWorkManager;
|
import com.info.sn.network.NetWorkManager;
|
||||||
import com.info.sn.network.api.ScreenLock;
|
import com.info.sn.network.api.ScreenLock;
|
||||||
import com.info.sn.utils.ApkUtils;
|
import com.info.sn.utils.SPUtils;
|
||||||
import com.info.sn.utils.ForegroundAppUtil;
|
|
||||||
import com.info.sn.utils.TimeUtils;
|
import com.info.sn.utils.TimeUtils;
|
||||||
import com.info.sn.utils.Utils;
|
import com.info.sn.utils.Utils;
|
||||||
|
|
||||||
@@ -103,23 +103,38 @@ public class InitJpushServer extends Service {
|
|||||||
showFloatingWindow("屏幕已锁定");
|
showFloatingWindow("屏幕已锁定");
|
||||||
}
|
}
|
||||||
screenlocked = true;
|
screenlocked = true;
|
||||||
|
SPUtils.put(InitJpushServer.this, LOCK_STATE, 1);
|
||||||
} else {
|
} else {
|
||||||
if (!timelocked) {
|
if (!timelocked) {
|
||||||
hideFloatingWindow();
|
hideFloatingWindow();
|
||||||
}
|
}
|
||||||
screenlocked = false;
|
screenlocked = false;
|
||||||
|
SPUtils.put(InitJpushServer.this, LOCK_STATE, 0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!timelocked) {
|
if (!timelocked) {
|
||||||
hideFloatingWindow();
|
hideFloatingWindow();
|
||||||
}
|
}
|
||||||
screenlocked = false;
|
screenlocked = false;
|
||||||
|
SPUtils.put(InitJpushServer.this, LOCK_STATE, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Throwable e) {
|
public void onError(Throwable e) {
|
||||||
|
Log.e("getScreenLockState", "onError: " + e.getMessage());
|
||||||
|
int is_screen_lock = (int) SPUtils.get(InitJpushServer.this, LOCK_STATE, 0);
|
||||||
|
if (is_screen_lock == 1) {
|
||||||
|
if (!timelocked) {
|
||||||
|
showFloatingWindow("屏幕已锁定");
|
||||||
|
}
|
||||||
|
screenlocked = true;
|
||||||
|
} else {
|
||||||
|
if (!timelocked) {
|
||||||
|
hideFloatingWindow();
|
||||||
|
}
|
||||||
|
screenlocked = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -137,6 +152,8 @@ public class InitJpushServer extends Service {
|
|||||||
boolean screenlocked = false;
|
boolean screenlocked = false;
|
||||||
boolean timelocked = false;
|
boolean timelocked = false;
|
||||||
|
|
||||||
|
private static final String LOCK_STATE = "SCRENN_LOOCKED_STATE";
|
||||||
|
|
||||||
private void showFloatingWindow(String name) {
|
private void showFloatingWindow(String name) {
|
||||||
if (Settings.canDrawOverlays(this)) {
|
if (Settings.canDrawOverlays(this)) {
|
||||||
// 获取WindowManager服务
|
// 获取WindowManager服务
|
||||||
@@ -159,7 +176,7 @@ public class InitJpushServer extends Service {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (null == topView) {
|
if (null == topView) {
|
||||||
topView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.activity_top, null);
|
topView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.activity_screen_lock, null);
|
||||||
TextView textView = topView.findViewById(R.id.textView);
|
TextView textView = topView.findViewById(R.id.textView);
|
||||||
textView.setText(name);
|
textView.setText(name);
|
||||||
} else {
|
} else {
|
||||||
@@ -173,17 +190,26 @@ public class InitJpushServer extends Service {
|
|||||||
// 设置LayoutParam
|
// 设置LayoutParam
|
||||||
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
|
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
layoutParams.type = WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
|
||||||
|
//TYPE_SYSTEM_OVERLAY可以下滑通知栏
|
||||||
|
// layoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
|
||||||
} else {
|
} else {
|
||||||
layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
|
layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
|
||||||
}
|
}
|
||||||
layoutParams.flags = WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
|
layoutParams.flags |= WindowManager.LayoutParams.FLAG_BLUR_BEHIND
|
||||||
|
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
|
||||||
|
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
|
||||||
layoutParams.format = PixelFormat.RGBA_8888;
|
layoutParams.format = PixelFormat.RGBA_8888;
|
||||||
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
|
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||||
layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
|
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||||
|
//systemUiVisibility 关闭通知栏和导航栏
|
||||||
|
|
||||||
|
layoutParams.systemUiVisibility =
|
||||||
|
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||||
|
| View.SYSTEM_UI_FLAG_IMMERSIVE
|
||||||
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
|
||||||
layoutParams.x = 0;
|
layoutParams.x = 0;
|
||||||
layoutParams.y = 0;
|
layoutParams.y = 0;
|
||||||
|
|
||||||
// 将悬浮窗控件添加到WindowManager
|
// 将悬浮窗控件添加到WindowManager
|
||||||
windowManager.addView(topView, layoutParams);
|
windowManager.addView(topView, layoutParams);
|
||||||
topView.setTag("added");
|
topView.setTag("added");
|
||||||
|
|||||||
BIN
app/src/main/libs/classes.jar
Normal file
BIN
app/src/main/libs/classes.jar
Normal file
Binary file not shown.
@@ -5,13 +5,13 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@color/gray"
|
android:background="@color/gray"
|
||||||
tools:context=".activity.TopActivity">
|
tools:context=".activity.ScreenLockActivity">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textView"
|
android:id="@+id/textView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="TextView"
|
android:text="屏幕已锁定"
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
@@ -5,13 +5,13 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@color/gray"
|
android:background="@color/gray"
|
||||||
tools:context=".activity.TopActivity">
|
tools:context=".activity.ScreenLockActivity">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textView"
|
android:id="@+id/textView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="TextView"
|
android:text="屏幕已锁定"
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
@@ -20,6 +20,12 @@ allprojects {
|
|||||||
jcenter()
|
jcenter()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
gradle.projectsEvaluated {
|
||||||
|
tasks.withType(JavaCompile) {
|
||||||
|
//设置jar相对包路径或绝对路径
|
||||||
|
options.compilerArgs.add('-Xbootclasspath/p:app/src/main/libs/classes.jar')
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task clean(type: Delete) {
|
task clean(type: Delete) {
|
||||||
|
|||||||
Reference in New Issue
Block a user