├── .gitignore ├── .idea ├── caches │ └── build_file_checksums.ser ├── codeStyles │ └── Project.xml ├── dictionaries │ └── ssaurel.xml ├── encodings.xml ├── gradle.xml ├── jarRepositories.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── ssaurel │ │ └── lockdevice │ │ ├── MainActivity.java │ │ └── MyAdmin.java │ └── res │ ├── layout │ └── activity_main.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml │ └── xml │ └── policies.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssaurel/LockScreenDevice/cc6d3bd570af8ef7037a8089863c29647d97c1ff/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | xmlns:android 11 | 12 | ^$ 13 | 14 | 15 | 16 |
17 |
18 | 19 | 20 | 21 | xmlns:.* 22 | 23 | ^$ 24 | 25 | 26 | BY_NAME 27 | 28 |
29 |
30 | 31 | 32 | 33 | .*:id 34 | 35 | http://schemas.android.com/apk/res/android 36 | 37 | 38 | 39 |
40 |
41 | 42 | 43 | 44 | .*:name 45 | 46 | http://schemas.android.com/apk/res/android 47 | 48 | 49 | 50 |
51 |
52 | 53 | 54 | 55 | name 56 | 57 | ^$ 58 | 59 | 60 | 61 |
62 |
63 | 64 | 65 | 66 | style 67 | 68 | ^$ 69 | 70 | 71 | 72 |
73 |
74 | 75 | 76 | 77 | .* 78 | 79 | ^$ 80 | 81 | 82 | BY_NAME 83 | 84 |
85 |
86 | 87 | 88 | 89 | .* 90 | 91 | http://schemas.android.com/apk/res/android 92 | 93 | 94 | ANDROID_ATTRIBUTE_ORDER 95 | 96 |
97 |
98 | 99 | 100 | 101 | .* 102 | 103 | .* 104 | 105 | 106 | BY_NAME 107 | 108 |
109 |
110 |
111 |
112 |
113 |
-------------------------------------------------------------------------------- /.idea/dictionaries/ssaurel.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | 34 | 35 | 39 | 40 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 31 | 48 | 49 | 50 | 51 | 52 | 53 | 55 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LockScreenDevice 2 | 3 | Lock Screen Device App Tutorial for Android. 4 | 5 | The tutorial is available on Medium : https://medium.com/@ssaurel/creating-a-lock-screen-device-app-for-android-4ec6576b92e0 6 | 7 | You can also watch the tutorial on YouTube on the SSaurel's Channel : 8 | 9 | [![Tutorial on the SSaurel's Channel](https://img.youtube.com/vi/JJcbB4FwtLY/0.jpg)](https://www.youtube.com/watch?v=JJcbB4FwtLY) 10 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 30 5 | 6 | defaultConfig { 7 | applicationId "com.ssaurel.lockdevice" 8 | minSdkVersion 15 9 | targetSdkVersion 30 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | implementation 'androidx.appcompat:appcompat:1.2.0' 25 | } 26 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/ssaurel/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/ssaurel/lockdevice/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.ssaurel.lockdevice; 2 | 3 | import android.app.Activity; 4 | import android.app.ActivityManager; 5 | import android.app.admin.DevicePolicyManager; 6 | import android.content.ComponentName; 7 | import android.content.Intent; 8 | import android.os.Bundle; 9 | import android.view.View; 10 | import android.widget.Button; 11 | import android.widget.Toast; 12 | 13 | import androidx.appcompat.app.AppCompatActivity; 14 | 15 | public class MainActivity extends AppCompatActivity implements View.OnClickListener{ 16 | 17 | private Button lock, disable, enable; 18 | public static final int RESULT_ENABLE = 11; 19 | private DevicePolicyManager devicePolicyManager; 20 | private ActivityManager activityManager; 21 | private ComponentName compName; 22 | 23 | @Override 24 | public void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.activity_main); 27 | devicePolicyManager = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE); 28 | activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); 29 | compName = new ComponentName(this, MyAdmin.class); 30 | 31 | lock = (Button) findViewById(R.id.lock); 32 | enable = (Button) findViewById(R.id.enableBtn); 33 | disable = (Button) findViewById(R.id.disableBtn); 34 | lock.setOnClickListener(this); 35 | enable.setOnClickListener(this); 36 | disable.setOnClickListener(this); 37 | } 38 | 39 | @Override 40 | protected void onResume() { 41 | super.onResume(); 42 | boolean isActive = devicePolicyManager.isAdminActive(compName); 43 | disable.setVisibility(isActive ? View.VISIBLE : View.GONE); 44 | enable.setVisibility(isActive ? View.GONE : View.VISIBLE); 45 | } 46 | 47 | @Override 48 | public void onClick(View view) { 49 | if (view == lock) { 50 | boolean active = devicePolicyManager.isAdminActive(compName); 51 | 52 | if (active) { 53 | devicePolicyManager.lockNow(); 54 | } else { 55 | Toast.makeText(this, "You need to enable the Admin Device Features", Toast.LENGTH_SHORT).show(); 56 | } 57 | 58 | } else if (view == enable) { 59 | 60 | Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); 61 | intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName); 62 | intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Additional text explaining why we need this permission"); 63 | startActivityForResult(intent, RESULT_ENABLE); 64 | 65 | } else if (view == disable) { 66 | devicePolicyManager.removeActiveAdmin(compName); 67 | disable.setVisibility(View.GONE); 68 | enable.setVisibility(View.VISIBLE); 69 | } 70 | } 71 | 72 | @Override 73 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 74 | switch(requestCode) { 75 | case RESULT_ENABLE : 76 | if (resultCode == Activity.RESULT_OK) { 77 | Toast.makeText(MainActivity.this, "You have enabled the Admin Device features", Toast.LENGTH_SHORT).show(); 78 | } else { 79 | Toast.makeText(MainActivity.this, "Problem to enable the Admin Device features", Toast.LENGTH_SHORT).show(); 80 | } 81 | break; 82 | } 83 | 84 | super.onActivityResult(requestCode, resultCode, data); 85 | } 86 | } 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /app/src/main/java/com/ssaurel/lockdevice/MyAdmin.java: -------------------------------------------------------------------------------- 1 | package com.ssaurel.lockdevice; 2 | 3 | import android.annotation.NonNull; 4 | import android.app.admin.DeviceAdminReceiver; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.widget.Toast; 8 | 9 | /** 10 | * Created by ssaurel on 04/09/2017. 11 | */ 12 | public class MyAdmin extends DeviceAdminReceiver { 13 | 14 | @Override 15 | public void onEnabled(@NonNull Context context, @NonNull Intent intent) { 16 | Toast.makeText(context, "Device Admin : enabled", Toast.LENGTH_SHORT).show(); 17 | } 18 | 19 | @Override 20 | public void onDisabled(@NonNull Context context, @NonNull Intent intent) { 21 | Toast.makeText(context, "Device Admin : disabled", Toast.LENGTH_SHORT).show(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 |