Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/devKotlin'
Browse files Browse the repository at this point in the history
  • Loading branch information
CraftsmanHyj committed Jul 13, 2022
2 parents 5611846 + 2f96079 commit ac09f14
Show file tree
Hide file tree
Showing 29 changed files with 2,121 additions and 442 deletions.
31 changes: 15 additions & 16 deletions Demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ android {
applicationId "com.hyj.permission.demo"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
versionCode 4
versionName "2.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

signingConfigs {
releaseSign { //正式签名
keyAlias KEY_ALIAS
keyPassword KEY_PASSWORD
storeFile file(STORE_FILE)
storePassword STORE_PASSWORD
}
}

// signingConfigs {
// releaseSign { //正式签名
// keyAlias KEY_ALIAS
// keyPassword KEY_PASSWORD
// storeFile file(STORE_FILE)
// storePassword STORE_PASSWORD
// }
// }

buildTypes {
release {
Expand All @@ -34,7 +33,7 @@ android {
minifyEnabled true //编译时是否混淆
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

signingConfig signingConfigs.releaseSign //签名信息
// signingConfig signingConfigs.releaseSign //签名信息
}
}

Expand All @@ -50,10 +49,10 @@ android {
//确定输出文件名
def today = new Date()
def path = ((project.name != "app") ? project.name : rootProject.name.replace(" ", "")) + "_" +
variant.flavorName + "_" +
//variant.flavorName + "_" +
variant.buildType.name + "_" +
variant.versionName + "_" +
today.format('yyyyMMddHHmm') +
//today.format('yyyyMMddHHmm') +
".apk"

variant.outputs.forEach {
Expand Down Expand Up @@ -96,6 +95,6 @@ dependencies {
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

implementation files("../docs/SimplePermission-V1.0.0.aar")
// implementation project(path: ':Permission')
// implementation files("../docs/SimplePermission-V1.0.0.aar")
implementation project(path: ':Permission')
}
92 changes: 75 additions & 17 deletions Demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,117 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.hyj.permission.demo">

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"
tools:ignore="CoarseFineLocation" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<!--危险权限,需要动态申请-->
<!--权限组:CALENDAR-->
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<!--权限组:CAMERA-->
<uses-permission android:name="android.permission.CAMERA" />
<!--权限组:CONTACTS-->
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!--权限组:LOCATION-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<!--权限组:MICROPHONE-->
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<!--权限组:PHONE-->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
<uses-permission android:name="android.permission.ADD_VOICEMAIL" />
<uses-permission android:name="android.permission.USE_SIP" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<!--权限组:SENSORS-->
<uses-permission android:name="android.permission.BODY_SENSORS" />
<!--权限组:SMS-->
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_WAP_PUSH" />
<uses-permission android:name="android.permission.RECEIVE_MMS" />
<!--权限组:STORAGE-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<!--权限组:-->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<!--权限组:-->
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
<!--权限组:-->
<uses-permission
android:name="android.permission.WRITE_SETTINGS"
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />
<!--权限组:-->
<uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<!--权限组:-->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<!--权限组:-->
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />

<!--正常权限,不需要动态申请-->
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
<uses-permission android:name="android.permission.GET_PACKAGE_SIZE" />
<uses-permission android:name="android.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.REORDER_TASKS" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.SET_ALARM" />
<uses-permission
android:name="android.permission.SET_TIME_ZONE"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" />
<uses-permission android:name="android.permission.TRANSMIT_IR" />
<uses-permission android:name="android.permission.UNINSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.SimplePermission"
tools:targetApi="31">
<meta-data
android:name="ScopedStorage"
android:value="true" />

<activity
android:name=".MainActivity"
android:exported="true">
Expand All @@ -65,6 +123,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</application>
</manifest>
85 changes: 65 additions & 20 deletions Demo/src/main/java/com/hyj/permission/demo/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.hyj.permission.demo

import android.Manifest
import android.Manifest.permission.READ_CALENDAR
import android.Manifest.permission.*
import android.os.Build
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.hyj.lib.permission.gps.registerForGpsResult
Expand All @@ -10,13 +10,13 @@ import com.hyj.lib.permission.registerForPermissionResult
import com.hyj.permission.demo.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {
private val singlePermissionLauncher = registerForPermissionResult<String> {
private val singlePermissionLauncher = registerForPermissionResult {
onGranted { showToast("单权限:同意了权限请求") }
onDenied { showToast("单权限:拒绝了权限") }
onPermanentlyDeniedTip { "单权限:运行APP需要这几个权限,请授权。" }
}

private val multiPersmissionLauncher = registerForPermissionResult<Array<String>> {
private val multiPermissionLauncher = registerForPermissionResult {
onGranted { showToast("多权限:同意了权限请求") }
onDenied { showToast("多权限:拒绝了权限") }
onPermanentlyDeniedTip { "多权限:运行APP需要这几个权限,请授权。" }
Expand All @@ -28,9 +28,7 @@ class MainActivity : AppCompatActivity() {
onRequestTip { "测试逻辑,测试是否可以准确检查GPS状态!" }
}

private val mBinding: ActivityMainBinding by lazy {
ActivityMainBinding.inflate(layoutInflater)
}
private val mBinding: ActivityMainBinding by lazy { ActivityMainBinding.inflate(layoutInflater) }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -39,22 +37,69 @@ class MainActivity : AppCompatActivity() {
initListener()
}

private fun initListener() {
mBinding.btnSinglePermission.setOnClickListener {
singlePermissionLauncher.launchP(READ_CALENDAR)
}
private fun initListener() = mBinding.run {
btnCheckGPSStatus.setOnClickListener { gpsLauncher.launch() }

mBinding.btnMultiPermission.setOnClickListener {
val multiplePermission = arrayOf(
Manifest.permission.CAMERA,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
btnSinglePermission.setOnClickListener {
//"android.permission.NOTIFICATION_SERVICE"
singlePermissionLauncher.launchP(this@MainActivity, RECORD_AUDIO)
}
btnMultiPermission.setOnClickListener {
val multiplePermission = arrayOf(CAMERA, READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE)
multiPermissionLauncher.launchP(this@MainActivity, *multiplePermission)
}
btnLocationGroup.setOnClickListener {
val localPermission =
arrayOf(ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION, ACCESS_BACKGROUND_LOCATION)
multiPermissionLauncher.launchP(this@MainActivity, *localPermission)
}
btnBlueTooth.setOnClickListener {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
showToast("当前版本不是 Android 12 及以上,旧版本的需要定位权限才能进行扫描蓝牙")
}
val blueTooth = arrayOf(BLUETOOTH_SCAN, BLUETOOTH_CONNECT, BLUETOOTH_ADVERTISE)
multiPermissionLauncher.launch(blueTooth)
}
btnNewStorage.setOnClickListener {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) {
showToast("当前版本不是 Android 11 及以上,会自动变更为旧版的请求方式")
}
singlePermissionLauncher.launchP(this@MainActivity, MANAGE_EXTERNAL_STORAGE)
}
btnInstall.setOnClickListener {
singlePermissionLauncher.launchP(this@MainActivity, REQUEST_INSTALL_PACKAGES)
}
btnWindow.setOnClickListener {
singlePermissionLauncher.launchP(this@MainActivity, SYSTEM_ALERT_WINDOW)
}
btnSetting.setOnClickListener {
singlePermissionLauncher.launchP(this@MainActivity, WRITE_SETTINGS)
}
btnNotification.setOnClickListener {
//Permission.NOTIFICATION_SERVICE
singlePermissionLauncher.launchP(
this@MainActivity, "android.permission.NOTIFICATION_SERVICE"
)
multiPersmissionLauncher.launchP(*multiplePermission)
}

mBinding.btnCheckGPSStatus.setOnClickListener {
gpsLauncher.launch()
btnNotificationListener.setOnClickListener {
singlePermissionLauncher.launchP(this@MainActivity, BIND_NOTIFICATION_LISTENER_SERVICE)
}
btnPackage.setOnClickListener {
singlePermissionLauncher.launchP(this@MainActivity, PACKAGE_USAGE_STATS)
}
btnAlarm.setOnClickListener {
singlePermissionLauncher.launchP(this@MainActivity, SCHEDULE_EXACT_ALARM)
}
btnNotDisturb.setOnClickListener {
singlePermissionLauncher.launchP(this@MainActivity, ACCESS_NOTIFICATION_POLICY)
}
btnIgnoreBattery.setOnClickListener {
singlePermissionLauncher.launchP(
this@MainActivity, REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
)
}
btnAppDetail.setOnClickListener {
singlePermissionLauncher.launchP(this@MainActivity)
}
}
}
Loading

0 comments on commit ac09f14

Please sign in to comment.