forked from CodingGay/BlackDex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
14 changed files
with
277 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package top.niunaijun.blackdex.util | ||
|
||
import java.io.File | ||
|
||
/** | ||
* | ||
* @Description: file util | ||
* @Author: wukaicheng | ||
* @CreateDate: 2021/5/30 20:25 | ||
*/ | ||
object FileUtil { | ||
|
||
fun filterApk(file: File):Boolean{ | ||
return (file.extension == "apk") or file.isDirectory | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
app/src/main/java/top/niunaijun/blackdex/view/base/PermissionActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package top.niunaijun.blackdex.view.base | ||
|
||
import android.Manifest | ||
import android.content.Intent | ||
import android.content.pm.PackageManager | ||
import android.net.Uri | ||
import android.os.Build | ||
import android.os.Environment | ||
import android.provider.Settings | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import androidx.annotation.RequiresApi | ||
import com.afollestad.materialdialogs.MaterialDialog | ||
import top.niunaijun.blackbox.utils.compat.BuildCompat | ||
import top.niunaijun.blackdex.R | ||
|
||
/** | ||
* | ||
* @Description:request permission activity | ||
* @Author: wukaicheng | ||
* @CreateDate: 2021/5/30 21:27 | ||
*/ | ||
open class PermissionActivity:BaseActivity() { | ||
|
||
protected var requestPermissionCallback: ((Boolean) -> Unit)? = null | ||
|
||
protected fun requestStoragePermission() { | ||
@RequiresApi(Build.VERSION_CODES.R) | ||
if (BuildCompat.isR()) { | ||
if (Environment.isExternalStorageManager()) { | ||
//fuck 请求了读取全部文件权限竟然还要申请普通读写权限 | ||
requestPermissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE) | ||
} else { | ||
MaterialDialog(this).show { | ||
title(R.string.grant_permission) | ||
message(res = R.string.request_storage_msg) | ||
negativeButton(res = R.string.request_later) { | ||
if(requestPermissionCallback!=null){ | ||
requestPermissionCallback!!(false) | ||
} | ||
} | ||
positiveButton(res = R.string.jump_grant) { | ||
val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION) | ||
intent.data = Uri.fromParts("package", packageName, null) | ||
startActivity(intent) | ||
} | ||
} | ||
} | ||
} else if (BuildCompat.isM() && checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) { | ||
requestPermissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE) | ||
}else{ | ||
if(requestPermissionCallback!=null){ | ||
requestPermissionCallback!!(true) | ||
} | ||
} | ||
} | ||
|
||
|
||
@RequiresApi(Build.VERSION_CODES.M) | ||
private val requestPermissionLauncher = | ||
registerForActivityResult(ActivityResultContracts.RequestPermission()) { | ||
if (it) { | ||
if(requestPermissionCallback!=null){ | ||
requestPermissionCallback!!(true) | ||
} | ||
} else { | ||
MaterialDialog(this).show { | ||
title(res = R.string.request_fail) | ||
message(res = R.string.denied_msg) | ||
if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { | ||
positiveButton(res = R.string.request_again) { | ||
requestStoragePermission() | ||
} | ||
|
||
} else { | ||
positiveButton(res = R.string.jump_grant) { | ||
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) | ||
val uri = Uri.fromParts("package", packageName, null) | ||
intent.data = uri | ||
startActivity(intent) | ||
} | ||
} | ||
negativeButton(res = R.string.request_later) { | ||
if(requestPermissionCallback!=null){ | ||
requestPermissionCallback!!(false) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
override fun onStart() { | ||
super.onStart() | ||
if(requestPermissionCallback!=null){ | ||
requestStoragePermission() | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.