Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
fengzhizi715 committed Nov 27, 2024
1 parent 4aba284 commit 083260f
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {

defaultConfig {
applicationId "cn.salesuite.saf.kotlin"
minSdkVersion cfg.minSdk
targetSdkVersion cfg.targetSdk
minSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<activity
android:name="cn.salesuite.saf.kotlin.activity.MainActivity"
android:exported="true"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name"
android:screenOrientation="portrait">
Expand Down Expand Up @@ -64,8 +65,13 @@

</application>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>

<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ package cn.salesuite.saf.kotlin.activity

import android.Manifest
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.provider.Settings
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import cn.salesuite.saf.kotlin.domain.User
import com.safframework.log.L
import com.safframework.log.printer.FilePrinter
import com.safframework.log.printer.file.FileBuilder


/**
*
* @FileName:
Expand All @@ -22,16 +28,29 @@ import com.safframework.log.printer.file.FileBuilder
class FilePrinterActivity : Activity() {

private lateinit var filePrinter:FilePrinter
private val REQUEST_CODE = 0



public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 0)
} else {
filePrinter = FileBuilder().folderPath("/storage/emulated/0/logs").build()
L.addPrinter(filePrinter);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {// Android 13 及以上

if (!Environment.isExternalStorageManager()) {
val intent = Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)
startActivityForResult(intent, REQUEST_CODE)
} else {
filePrinter = FileBuilder().folderPath("/storage/emulated/0/logs").build()
L.addPrinter(filePrinter)
}
} else { // Android 12 及以下
if (hasStoragePermissions(this)) {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), REQUEST_CODE)
} else {
filePrinter = FileBuilder().folderPath("/storage/emulated/0/logs").build()
L.addPrinter(filePrinter)
}
}

L.i("111321frehtyjuyikuloil'0[xwrgrtehcytbk8ynfggrgr4hytj")
Expand All @@ -56,10 +75,38 @@ class FilePrinterActivity : Activity() {
L.json(map3)
}

/**
* 权限检查
* @param context
* @return
*/
private fun hasStoragePermissions(context: Context): Boolean {
//版本判断,如果比android 13 就走正常的权限获取
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
val readPermission = ContextCompat.checkSelfPermission(
context,
Manifest.permission.READ_EXTERNAL_STORAGE
)
val writePermission = ContextCompat.checkSelfPermission(
context,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)
return readPermission == PackageManager.PERMISSION_GRANTED && writePermission == PackageManager.PERMISSION_GRANTED
} else {
val audioPermission =
ContextCompat.checkSelfPermission(context, Manifest.permission.READ_MEDIA_AUDIO)
val imagePermission =
ContextCompat.checkSelfPermission(context, Manifest.permission.READ_MEDIA_IMAGES)
val videoPermission =
ContextCompat.checkSelfPermission(context, Manifest.permission.READ_MEDIA_VIDEO)
return audioPermission == PackageManager.PERMISSION_GRANTED && imagePermission == PackageManager.PERMISSION_GRANTED && videoPermission == PackageManager.PERMISSION_GRANTED
}
}


override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {

if (requestCode==0) {

filePrinter = FileBuilder().folderPath("/storage/emulated/0/logs").build()
L.addPrinter(filePrinter)
}
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
ext {
configuration = [
buildToolsVersion: "29.0.2",
compileVersion : 29,
buildToolsVersion: "30.0.3",
compileVersion : 33,
minSdk : 15,
targetSdk : 29
targetSdk : 33
]

libraries = [
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.useAndroidX=true
android.useAndroidX=true
android.enableJetifier=true

0 comments on commit 083260f

Please sign in to comment.