├── .gitignore
├── .idea
├── .name
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── gradle.xml
├── inspectionProfiles
│ └── Project_Default.xml
├── jarRepositories.xml
├── misc.xml
├── runConfigurations.xml
└── vcs.xml
├── SourceApp
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── kuaima
│ │ └── sharefileforandroid11
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ └── friends.jpg
│ ├── java
│ │ └── com
│ │ │ └── kuaima
│ │ │ └── sharefileforandroid11
│ │ │ └── MainActivity.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.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
│ │ └── file_provider_paths.xml
│ └── test
│ └── java
│ └── com
│ └── kuaima
│ └── sharefileforandroid11
│ └── ExampleUnitTest.kt
├── build.gradle
├── destinationapp
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── kuaima
│ │ └── destinationapp
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── kuaima
│ │ │ └── destinationapp
│ │ │ └── MainActivity.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.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
│ └── test
│ └── java
│ └── com
│ └── kuaima
│ └── destinationapp
│ └── ExampleUnitTest.kt
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── manageexternalstorage
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── kuaima
│ │ └── manageexternalstorage
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── kuaima
│ │ │ └── manageexternalstorage
│ │ │ └── MainActivity.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.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
│ └── test
│ └── java
│ └── com
│ └── kuaima
│ └── manageexternalstorage
│ └── ExampleUnitTest.kt
├── packagevisibleoneapp
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── kuaima
│ │ └── packagevisibleoneapp
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── kuaima
│ │ │ └── packagevisibleoneapp
│ │ │ └── MainActivity.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.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
│ └── test
│ └── java
│ └── com
│ └── kuaima
│ └── packagevisibleoneapp
│ └── ExampleUnitTest.kt
├── packagevisiblesecondapp
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── kuaima
│ │ └── packagevisiblesecondapp
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── kuaima
│ │ │ └── packagevisiblesecondapp
│ │ │ └── MainActivity.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.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
│ └── test
│ └── java
│ └── com
│ └── kuaima
│ └── packagevisiblesecondapp
│ └── ExampleUnitTest.kt
├── saf
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── kuaima
│ │ └── saf
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ └── friends.jpg
│ ├── java
│ │ └── com
│ │ │ └── kuaima
│ │ │ └── saf
│ │ │ └── MainActivity.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.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
│ └── test
│ └── java
│ └── com
│ └── kuaima
│ └── saf
│ └── ExampleUnitTest.kt
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | Android11
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | xmlns:android
17 |
18 | ^$
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | xmlns:.*
28 |
29 | ^$
30 |
31 |
32 | BY_NAME
33 |
34 |
35 |
36 |
37 |
38 |
39 | .*:id
40 |
41 | http://schemas.android.com/apk/res/android
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | .*:name
51 |
52 | http://schemas.android.com/apk/res/android
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | name
62 |
63 | ^$
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | style
73 |
74 | ^$
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | .*
84 |
85 | ^$
86 |
87 |
88 | BY_NAME
89 |
90 |
91 |
92 |
93 |
94 |
95 | .*
96 |
97 | http://schemas.android.com/apk/res/android
98 |
99 |
100 | ANDROID_ATTRIBUTE_ORDER
101 |
102 |
103 |
104 |
105 |
106 |
107 | .*
108 |
109 | .*
110 |
111 |
112 | BY_NAME
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
26 |
27 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/SourceApp/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/SourceApp/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 30
7 | buildToolsVersion "30.0.2"
8 |
9 | defaultConfig {
10 | applicationId "com.kuaima.sharefileforandroid11"
11 | minSdkVersion 22
12 | targetSdkVersion 30
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: "libs", include: ["*.jar"])
29 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
30 | implementation 'androidx.core:core-ktx:1.3.1'
31 | implementation 'androidx.appcompat:appcompat:1.2.0'
32 | implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
33 | testImplementation 'junit:junit:4.12'
34 | androidTestImplementation 'androidx.test.ext:junit:1.1.2'
35 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
36 |
37 | }
--------------------------------------------------------------------------------
/SourceApp/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/SourceApp/src/androidTest/java/com/kuaima/sharefileforandroid11/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.kuaima.sharefileforandroid11
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.kuaima.sharefileforandroid11", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/SourceApp/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
28 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/SourceApp/src/main/assets/friends.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/SourceApp/src/main/assets/friends.jpg
--------------------------------------------------------------------------------
/SourceApp/src/main/java/com/kuaima/sharefileforandroid11/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.kuaima.sharefileforandroid11
2 |
3 | import android.content.ContentValues
4 | import android.content.Intent
5 | import android.net.Uri
6 | import android.os.Bundle
7 | import android.os.Environment
8 | import android.provider.MediaStore
9 | import android.util.Log
10 | import android.widget.Toast
11 | import androidx.appcompat.app.AppCompatActivity
12 | import androidx.core.content.FileProvider
13 | import kotlinx.android.synthetic.main.activity_main.*
14 | import java.io.File
15 | import java.io.FileInputStream
16 | import java.io.FileOutputStream
17 |
18 |
19 | class MainActivity : AppCompatActivity() {
20 | override fun onCreate(savedInstanceState: Bundle?) {
21 | super.onCreate(savedInstanceState)
22 | setContentView(R.layout.activity_main)
23 | fileProviderBtn.setOnClickListener {
24 | val fileProviderPath = fileProviderShare()
25 | if (fileProviderPath == null) {
26 | return@setOnClickListener
27 | }
28 |
29 | // dealFileProviderPath(fileProviderPath)
30 | val intent = Intent()
31 | //授权临时权限
32 | grantUriPermission(
33 | "com.kuaima.destinationapp",
34 | Uri.parse(fileProviderPath), Intent.FLAG_GRANT_READ_URI_PERMISSION
35 | )
36 | intent
37 | .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
38 | .setAction("android.intent.action.media.test")
39 | .addCategory(Intent.CATEGORY_DEFAULT)
40 | .putExtra("file_provider_uri", fileProviderPath)
41 | startActivity(intent)
42 | }
43 | mediaStoreBtn.setOnClickListener {
44 | val mediaStoreUri = mediaStore()
45 | if (mediaStoreUri != null) {
46 | val intent = Intent()
47 | intent
48 | .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
49 | .setAction("android.intent.action.media.test")
50 | .addCategory(Intent.CATEGORY_DEFAULT)
51 | .putExtra("media_store", mediaStoreUri)
52 |
53 | startActivity(intent)
54 | }
55 | }
56 |
57 | fileBtn.setOnClickListener {
58 | val fileShare = fileShare()
59 | val intent = Intent()
60 | intent
61 | .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
62 | .setAction("android.intent.action.media.test")
63 | .addCategory(Intent.CATEGORY_DEFAULT)
64 | .putExtra("file_path", fileShare)
65 | startActivity(intent)
66 | }
67 | }
68 |
69 |
70 | //通过MediaStore存储到公共目录再分享
71 | private fun mediaStore(): String? {
72 | val resolver = applicationContext.contentResolver
73 | val contentValues = ContentValues().apply {
74 | put(MediaStore.Images.Media.DISPLAY_NAME, "friends.jpg")
75 | }
76 |
77 | val uri = resolver
78 | .insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues)
79 |
80 | if (uri != null) {
81 | val outputStream = resolver.openOutputStream(uri)
82 | if (outputStream == null) {
83 | return null
84 | }
85 | val inputStream = this.assets.open("friends.jpg")
86 | val byteArray = ByteArray(1024)
87 | try {
88 | inputStream.use { input ->
89 | outputStream.use { output ->
90 | while (true) {
91 | val readLen = input.read(byteArray)
92 | if (readLen == -1) {
93 | break
94 | }
95 | outputStream.write(byteArray, 0, readLen)
96 | }
97 | }
98 | }
99 | } catch (e: Throwable) {
100 | Log.e("wfeii", "mediaStore e:$e")
101 | }
102 |
103 | }
104 | Log.e("wfeii", "mediaStore:$uri")
105 | return uri?.toString()
106 | }
107 |
108 | //通过FileProvider分享
109 | private fun fileProviderShare(): String? {
110 | val imagePath = File(this.getExternalFilesDir(null), "images")!!
111 | val file = File(imagePath, "friends_file_provider.jpg")
112 |
113 | if (!file.parentFile.exists()) {
114 | file.parentFile.mkdirs()
115 | }
116 |
117 | //更具获取Url
118 | val contentUri: Uri =
119 | FileProvider.getUriForFile(this, "com.kuaima.sharefileforandroid11.fileProvider", file)
120 | val fileOutputStream = contentResolver.openOutputStream(contentUri)
121 | if (fileOutputStream == null) {
122 | return null
123 | }
124 | val inputStream = this.assets.open("friends.jpg")
125 | val byteArray = ByteArray(1024)
126 | try {
127 | fileOutputStream.use { outputStream ->
128 | inputStream.use { inputStream ->
129 | while (true) {
130 | val readLen = inputStream.read(byteArray)
131 | if (readLen == -1) {
132 | break
133 | }
134 | outputStream.write(byteArray, 0, readLen)
135 | }
136 | }
137 | }
138 | } catch (e: Throwable) {
139 | Log.e("wfeii", "fileProviderShare e:$e")
140 | }
141 | Log.e("wfeii", "fileProviderShare:$contentUri")
142 | return contentUri.toString()
143 | }
144 |
145 | //通过File的方式分享
146 | private fun fileShare(): String {
147 | val file = File(
148 | Environment.getExternalStoragePublicDirectory(
149 | Environment.DIRECTORY_PICTURES
150 | ),
151 | "friends_file.jpg"
152 | )
153 | if (!file.parentFile.exists()) {
154 | file.mkdirs()
155 | }
156 | val fileOutputStream = FileOutputStream(file)
157 | val inputStream = this.assets.open("friends.jpg")
158 | val byteArray = ByteArray(1024)
159 | try {
160 | fileOutputStream.use { outputStream ->
161 | inputStream.use { inputStream ->
162 | while (true) {
163 | val readLen = inputStream.read(byteArray)
164 | if (readLen == -1) {
165 | break
166 | }
167 | outputStream.write(byteArray, 0, readLen)
168 | }
169 | }
170 | }
171 | } catch (e: Throwable) {
172 | Log.e("wfeii", "fileShare:$e")
173 | }
174 |
175 | return file.path
176 | }
177 | }
--------------------------------------------------------------------------------
/SourceApp/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/SourceApp/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/SourceApp/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
27 |
28 |
36 |
37 |
--------------------------------------------------------------------------------
/SourceApp/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/SourceApp/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/SourceApp/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/SourceApp/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/SourceApp/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/SourceApp/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/SourceApp/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/SourceApp/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/SourceApp/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/SourceApp/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/SourceApp/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/SourceApp/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/SourceApp/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/SourceApp/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/SourceApp/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/SourceApp/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/SourceApp/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/SourceApp/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/SourceApp/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/SourceApp/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/SourceApp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/SourceApp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/SourceApp/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 |
--------------------------------------------------------------------------------
/SourceApp/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ShareFileForAndroid11
3 |
--------------------------------------------------------------------------------
/SourceApp/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/SourceApp/src/main/res/xml/file_provider_paths.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
--------------------------------------------------------------------------------
/SourceApp/src/test/java/com/kuaima/sharefileforandroid11/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.kuaima.sharefileforandroid11
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | buildscript {
3 | ext.kotlin_version = "1.3.72"
4 | repositories {
5 | google()
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath "com.android.tools.build:gradle:4.0.0"
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | google()
20 | jcenter()
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
--------------------------------------------------------------------------------
/destinationapp/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/destinationapp/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 30
7 | buildToolsVersion "30.0.2"
8 |
9 | defaultConfig {
10 | applicationId "com.kuaima.destinationapp"
11 | minSdkVersion 22
12 | targetSdkVersion 30
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: "libs", include: ["*.jar"])
29 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
30 | implementation 'androidx.core:core-ktx:1.3.1'
31 | implementation 'androidx.appcompat:appcompat:1.2.0'
32 | implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
33 | testImplementation 'junit:junit:4.12'
34 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
35 | androidTestImplementation 'androidx.test.ext:junit:1.1.2'
36 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/destinationapp/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/destinationapp/src/androidTest/java/com/kuaima/destinationapp/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.kuaima.destinationapp
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.kuaima.destinationapp", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/destinationapp/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/destinationapp/src/main/java/com/kuaima/destinationapp/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.kuaima.destinationapp
2 |
3 | import android.Manifest
4 | import android.content.Intent
5 | import android.net.Uri
6 | import android.os.Bundle
7 | import android.util.Log
8 | import android.widget.Toast
9 | import androidx.appcompat.app.AppCompatActivity
10 | import androidx.core.content.PermissionChecker
11 | import java.io.File
12 | import java.io.FileInputStream
13 | import java.io.FileOutputStream
14 | import java.io.InputStream
15 |
16 | class MainActivity : AppCompatActivity() {
17 |
18 | override fun onCreate(savedInstanceState: Bundle?) {
19 | super.onCreate(savedInstanceState)
20 | setContentView(R.layout.activity_main)
21 | val intent = intent
22 | dealMediaStoreUrl(intent)
23 | dealFilePath(intent)
24 | dealFileProviderPath(intent)
25 | Manifest.permission.MANAGE_EXTERNAL_STORAGE
26 | }
27 |
28 | private fun dealMediaStoreUrl(intent: Intent?) {
29 | if (intent == null) {
30 | return
31 | }
32 | val mediaStoreUrl = intent.getStringExtra(MEDIA_STORE)
33 |
34 | if (mediaStoreUrl == null) {
35 | return
36 | }
37 | val readOnlyMode = "r"
38 | val fileDescriptor =
39 | contentResolver.openFileDescriptor(
40 | Uri.parse(mediaStoreUrl),
41 | readOnlyMode
42 | )?.fileDescriptor
43 | if (fileDescriptor == null) {
44 | return
45 | }
46 | val fileInputStream: InputStream = FileInputStream(fileDescriptor)
47 |
48 | val file = File(getExternalFilesDir(""), "mediaStore.jpg")
49 | val fileOutputStream = FileOutputStream(file)
50 | val byteArray = ByteArray(1024)
51 | try {
52 | fileInputStream.use { fileDescriptor ->
53 | fileOutputStream.use { fileOutputStream ->
54 | while (true) {
55 | val readLen = fileInputStream.read(byteArray)
56 | if (readLen == -1) {
57 | break
58 | }
59 | fileOutputStream.write(byteArray, 0, readLen)
60 | }
61 | }
62 | }
63 | } catch (e: Throwable) {
64 | Log.e("wfeii", "dealMediaStoreUrl:$e")
65 | }
66 |
67 | Toast.makeText(this, "复制成功", Toast.LENGTH_LONG).show()
68 | }
69 |
70 | private fun dealFilePath(intent: Intent?) {
71 | if (intent == null) {
72 | return
73 | }
74 | val filePath = intent.getStringExtra(FILE_PATH)
75 | if (filePath == null) {
76 | return
77 | }
78 | val file = File(getExternalFilesDir(""), "mediaStore_file.jpg")
79 | if (!file.parentFile.exists()) {
80 | file.parentFile.mkdirs()
81 | }
82 |
83 | val fileInputStream = FileInputStream(filePath)
84 |
85 | val fileOutputStream = FileOutputStream(file)
86 | val byteArray = ByteArray(1024)
87 | try {
88 | fileInputStream.use { fileInputStream ->
89 | fileOutputStream.use { fileOutputStream ->
90 | while (true) {
91 | val readLen = fileInputStream.read(byteArray)
92 | if (readLen == -1) {
93 | break
94 | }
95 | fileOutputStream.write(byteArray, 0, readLen)
96 | }
97 | }
98 | }
99 | } catch (t: Throwable) {
100 | Log.e("wfeii", "dealFilePath:$t")
101 | }
102 | Toast.makeText(this, "复制成功", Toast.LENGTH_LONG).show()
103 | }
104 |
105 | private fun dealFileProviderPath(intent: Intent?) {
106 | if (intent == null) {
107 | return
108 | }
109 | val fileProviderUri = intent.getStringExtra(FILE_PROVIDER_URI)
110 | if (fileProviderUri == null) {
111 | return
112 | }
113 |
114 | Log.e("wfeii", "dealFileProviderPath fileProviderUri:$fileProviderUri")
115 | val readOnlyMode = "r"
116 | val fileDescriptor =
117 | contentResolver.openFileDescriptor(
118 | Uri.parse(fileProviderUri), readOnlyMode
119 | )?.fileDescriptor
120 | if (fileDescriptor == null) {
121 | return
122 | }
123 |
124 | val inputStream = FileInputStream(fileDescriptor)
125 | val file = File(getExternalFilesDir(""), "file_provider_path.jpg")
126 | val fileOutputStream = FileOutputStream(file)
127 | val byteArray = ByteArray(1024)
128 | try {
129 | inputStream.use { fileDescriptor ->
130 | fileOutputStream.use { fileOutputStream ->
131 | while (true) {
132 | val readLen = inputStream.read(byteArray)
133 | if (readLen == -1) {
134 | break
135 | }
136 | fileOutputStream.write(byteArray, 0, readLen)
137 | }
138 | }
139 | }
140 | } catch (t: Throwable) {
141 | Log.e("wfeii", "t")
142 | }
143 | Toast.makeText(this, "复制成功", Toast.LENGTH_LONG).show()
144 | }
145 |
146 | override fun onNewIntent(intent: Intent?) {
147 | super.onNewIntent(intent)
148 | setIntent(intent)
149 | dealMediaStoreUrl(intent)
150 | dealFilePath(intent)
151 | dealFileProviderPath(intent)
152 | }
153 |
154 | companion object {
155 | private const val MEDIA_STORE = "media_store"
156 | private const val FILE_PATH = "file_path"
157 | private const val FILE_PROVIDER_URI = "file_provider_uri"
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/destinationapp/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/destinationapp/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/destinationapp/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
--------------------------------------------------------------------------------
/destinationapp/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/destinationapp/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/destinationapp/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/destinationapp/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/destinationapp/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/destinationapp/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/destinationapp/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/destinationapp/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/destinationapp/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/destinationapp/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/destinationapp/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/destinationapp/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/destinationapp/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/destinationapp/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/destinationapp/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/destinationapp/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/destinationapp/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/destinationapp/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/destinationapp/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/destinationapp/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/destinationapp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/destinationapp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/destinationapp/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 |
--------------------------------------------------------------------------------
/destinationapp/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DestinationApp
3 |
--------------------------------------------------------------------------------
/destinationapp/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/destinationapp/src/test/java/com/kuaima/destinationapp/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.kuaima.destinationapp
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Sep 06 10:37:01 CST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/manageexternalstorage/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/manageexternalstorage/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 30
7 | buildToolsVersion "30.0.2"
8 |
9 | defaultConfig {
10 | applicationId "com.kuaima.manageexternalstorage"
11 | minSdkVersion 23
12 | targetSdkVersion 30
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: "libs", include: ["*.jar"])
29 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
30 | implementation 'androidx.core:core-ktx:1.3.1'
31 | implementation 'androidx.appcompat:appcompat:1.2.0'
32 | implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
33 | testImplementation 'junit:junit:4.12'
34 | androidTestImplementation 'androidx.test.ext:junit:1.1.2'
35 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
36 | implementation 'com.google.android.material:material:1.2.1'
37 | }
38 |
--------------------------------------------------------------------------------
/manageexternalstorage/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/manageexternalstorage/src/androidTest/java/com/kuaima/manageexternalstorage/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.kuaima.manageexternalstorage
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.kuaima.manageexternalstorage", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/manageexternalstorage/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/manageexternalstorage/src/main/java/com/kuaima/manageexternalstorage/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.kuaima.manageexternalstorage
2 |
3 | import android.content.Intent
4 | import android.net.Uri
5 | import android.os.Bundle
6 | import android.os.Environment
7 | import android.provider.Settings
8 | import android.util.Log
9 | import androidx.appcompat.app.AppCompatActivity
10 | import com.google.android.material.snackbar.Snackbar
11 | import java.io.File
12 | import java.io.FileOutputStream
13 | import java.io.IOException
14 |
15 | class MainActivity : AppCompatActivity() {
16 | companion object {
17 | private val REQUEST_SETTINGS_CODE = 20
18 | }
19 |
20 | override fun onCreate(savedInstanceState: Bundle?) {
21 | super.onCreate(savedInstanceState)
22 | setContentView(R.layout.activity_main)
23 | //判断是否有所有文件访问权限
24 | if (!Environment.isExternalStorageManager()) {
25 | Snackbar.make(
26 | findViewById(R.id.container), "需要打开权限才能使用该功能,您也可以前往设置->应用。。。开启权限",
27 | Snackbar.LENGTH_INDEFINITE
28 | )
29 | .setAction("确定") {
30 | //跳转到所有文件访问权限开启
31 | val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
32 | intent.setData(Uri.parse("package:$packageName"));
33 | startActivityForResult(intent, REQUEST_SETTINGS_CODE)
34 | }
35 | .show()
36 | }
37 | }
38 |
39 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
40 | super.onActivityResult(requestCode, resultCode, data)
41 | Log.e("wfeii", "requestCode:$requestCode resultCode:$resultCode data:${data}")
42 | if (!Environment.isExternalStorageManager()) {
43 | Snackbar.make(
44 | findViewById(R.id.container), "需要打开权限才能使用该功能,您也可以前往设置->应用。。。开启权限",
45 | Snackbar.LENGTH_INDEFINITE
46 | )
47 | .setAction("确定") {
48 | //跳转到所有文件访问权限开启
49 | val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
50 | intent.setData(Uri.parse("package:$packageName"));
51 | startActivityForResult(intent, REQUEST_SETTINGS_CODE)
52 | }
53 | .show()
54 | }
55 |
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/manageexternalstorage/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/manageexternalstorage/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/manageexternalstorage/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
--------------------------------------------------------------------------------
/manageexternalstorage/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/manageexternalstorage/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/manageexternalstorage/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/manageexternalstorage/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/manageexternalstorage/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/manageexternalstorage/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/manageexternalstorage/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/manageexternalstorage/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/manageexternalstorage/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/manageexternalstorage/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/manageexternalstorage/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/manageexternalstorage/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/manageexternalstorage/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/manageexternalstorage/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/manageexternalstorage/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/manageexternalstorage/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/manageexternalstorage/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/manageexternalstorage/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/manageexternalstorage/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/manageexternalstorage/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/manageexternalstorage/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/manageexternalstorage/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/manageexternalstorage/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 |
--------------------------------------------------------------------------------
/manageexternalstorage/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | manageExternalStorage
3 |
--------------------------------------------------------------------------------
/manageexternalstorage/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/manageexternalstorage/src/test/java/com/kuaima/manageexternalstorage/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.kuaima.manageexternalstorage
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/packagevisibleoneapp/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/packagevisibleoneapp/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 30
7 | buildToolsVersion "30.0.2"
8 |
9 | defaultConfig {
10 | applicationId "com.kuaima.packagevisibleoneapp"
11 | minSdkVersion 22
12 | targetSdkVersion 30
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: "libs", include: ["*.jar"])
29 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
30 | implementation 'androidx.core:core-ktx:1.3.1'
31 | implementation 'androidx.appcompat:appcompat:1.2.0'
32 | implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
33 | testImplementation 'junit:junit:4.12'
34 | androidTestImplementation 'androidx.test.ext:junit:1.1.2'
35 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/packagevisibleoneapp/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/androidTest/java/com/kuaima/packagevisibleoneapp/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.kuaima.packagevisibleoneapp
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.kuaima.packagevisibleoneapp", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/main/java/com/kuaima/packagevisibleoneapp/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.kuaima.packagevisibleoneapp
2 |
3 | import android.content.Intent
4 | import android.content.pm.PackageManager.MATCH_DEFAULT_ONLY
5 | import androidx.appcompat.app.AppCompatActivity
6 | import android.os.Bundle
7 | import android.text.TextUtils
8 | import android.util.Log
9 | import android.widget.Toast
10 | import kotlinx.android.synthetic.main.activity_main.*
11 |
12 | class MainActivity : AppCompatActivity() {
13 |
14 | override fun onCreate(savedInstanceState: Bundle?) {
15 | super.onCreate(savedInstanceState)
16 | setContentView(R.layout.activity_main)
17 | start_activity.setOnClickListener {
18 | val intent = Intent()
19 | intent.action = "android.intent.action.test_hello_world"
20 | intent.addCategory(Intent.CATEGORY_DEFAULT)
21 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
22 | val packageManager = packageManager
23 | val queryIntentActivities =
24 | packageManager.queryIntentActivities(intent, MATCH_DEFAULT_ONLY)
25 | for (activity in queryIntentActivities) {
26 | Log.e("wfeii", "activity : $activity")
27 | }
28 | if (isInstalled()) {
29 | startActivity(intent)
30 | } else {
31 | Toast.makeText(this, "请安装应用", Toast.LENGTH_SHORT).show()
32 | }
33 | }
34 | }
35 |
36 | private fun isInstalled(): Boolean {
37 | val installedPackages = packageManager.getInstalledPackages(0)
38 | for (installedPackage in installedPackages) {
39 | if (TextUtils.equals(
40 | installedPackage.packageName,
41 | "com.kuaima.packagevisiblesecondapp"
42 | )
43 | ) {
44 | return true
45 | }
46 | }
47 | return false
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/packagevisibleoneapp/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/packagevisibleoneapp/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/packagevisibleoneapp/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/packagevisibleoneapp/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/packagevisibleoneapp/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/packagevisibleoneapp/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/packagevisibleoneapp/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/packagevisibleoneapp/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/packagevisibleoneapp/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/packagevisibleoneapp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 |
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | packageVisibleOneApp
3 | hahah$s,$s
4 |
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/packagevisibleoneapp/src/test/java/com/kuaima/packagevisibleoneapp/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.kuaima.packagevisibleoneapp
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/packagevisiblesecondapp/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/packagevisiblesecondapp/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 30
7 | buildToolsVersion "30.0.2"
8 |
9 | defaultConfig {
10 | applicationId "com.kuaima.packagevisiblesecondapp"
11 | minSdkVersion 22
12 | targetSdkVersion 30
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: "libs", include: ["*.jar"])
29 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
30 | implementation 'androidx.core:core-ktx:1.3.1'
31 | implementation 'androidx.appcompat:appcompat:1.2.0'
32 | implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
33 | testImplementation 'junit:junit:4.12'
34 | androidTestImplementation 'androidx.test.ext:junit:1.1.2'
35 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/packagevisiblesecondapp/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/androidTest/java/com/kuaima/packagevisiblesecondapp/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.kuaima.packagevisiblesecondapp
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.kuaima.packagevisiblesecondapp", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/main/java/com/kuaima/packagevisiblesecondapp/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.kuaima.packagevisiblesecondapp
2 |
3 | import androidx.appcompat.app.AppCompatActivity
4 | import android.os.Bundle
5 |
6 | class MainActivity : AppCompatActivity() {
7 |
8 | override fun onCreate(savedInstanceState: Bundle?) {
9 | super.onCreate(savedInstanceState)
10 | setContentView(R.layout.activity_main)
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/packagevisiblesecondapp/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/packagevisiblesecondapp/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/packagevisiblesecondapp/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/packagevisiblesecondapp/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/packagevisiblesecondapp/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/packagevisiblesecondapp/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/packagevisiblesecondapp/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/packagevisiblesecondapp/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/packagevisiblesecondapp/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/packagevisiblesecondapp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 |
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | packageVisibleSecondApp
3 |
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/packagevisiblesecondapp/src/test/java/com/kuaima/packagevisiblesecondapp/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.kuaima.packagevisiblesecondapp
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/saf/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/saf/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 30
7 | buildToolsVersion "30.0.2"
8 |
9 | defaultConfig {
10 | applicationId "com.kuaima.saf"
11 | minSdkVersion 22
12 | targetSdkVersion 30
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: "libs", include: ["*.jar"])
29 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
30 | implementation 'androidx.core:core-ktx:1.3.1'
31 | implementation 'androidx.appcompat:appcompat:1.2.0'
32 | implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
33 | testImplementation 'junit:junit:4.12'
34 | androidTestImplementation 'androidx.test.ext:junit:1.1.2'
35 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
36 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
37 | }
38 |
--------------------------------------------------------------------------------
/saf/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/saf/src/androidTest/java/com/kuaima/saf/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.kuaima.saf
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.kuaima.saf", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/saf/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/saf/src/main/assets/friends.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/saf/src/main/assets/friends.jpg
--------------------------------------------------------------------------------
/saf/src/main/java/com/kuaima/saf/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.kuaima.saf
2 |
3 | import android.app.Activity
4 | import android.content.Intent
5 | import android.os.Bundle
6 | import android.util.Log
7 | import androidx.appcompat.app.AppCompatActivity
8 | import androidx.documentfile.provider.DocumentFile
9 | import kotlinx.android.synthetic.main.activity_main.*
10 | import java.io.File
11 | import java.io.FileOutputStream
12 | import java.io.IOException
13 |
14 | class MainActivity : AppCompatActivity() {
15 |
16 | override fun onCreate(savedInstanceState: Bundle?) {
17 | super.onCreate(savedInstanceState)
18 | setContentView(R.layout.activity_main)
19 | create_file.setOnClickListener {
20 | val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
21 | addCategory(Intent.CATEGORY_OPENABLE)
22 | type = "image/jpeg"
23 | putExtra(Intent.EXTRA_TITLE, "invoice.jpg")
24 | }
25 | startActivityForResult(intent, REQUEST_CODE_CREATE_FILE)
26 | }
27 |
28 | open_file.setOnClickListener {
29 | val intent = Intent().apply {
30 | action = Intent.ACTION_OPEN_DOCUMENT
31 | addCategory(Intent.CATEGORY_OPENABLE)
32 | type = "image/jpeg"
33 | }
34 | startActivityForResult(intent, REQUEST_CODE_OPEN_FILE)
35 | }
36 |
37 | open_file_tree.setOnClickListener {
38 | val intent = Intent().apply {
39 | action = Intent.ACTION_OPEN_DOCUMENT_TREE
40 | }
41 | startActivityForResult(intent, REQUEST_CODE_OPEN_FILE_TREE)
42 | }
43 | }
44 |
45 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
46 | super.onActivityResult(requestCode, resultCode, data)
47 | if (resultCode != Activity.RESULT_OK) {
48 | return
49 | }
50 | if (data == null) {
51 | return
52 | }
53 | val uri = data.data ?: return
54 | when (requestCode) {
55 |
56 | REQUEST_CODE_CREATE_FILE -> {
57 | val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or
58 | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
59 | contentResolver.takePersistableUriPermission(uri, takeFlags)
60 | val fromSingleUri = DocumentFile.fromSingleUri(this, uri)
61 | val outputStream = contentResolver.openOutputStream(uri) ?: return
62 | val inputStream = this.assets.open("friends.jpg")
63 | try {
64 | outputStream.use { outputStream ->
65 | inputStream.use { inputStream ->
66 | val byteArray = ByteArray(1024)
67 | while (true) {
68 | val readCount = inputStream.read(byteArray)
69 | if (readCount == -1) {
70 | break
71 | }
72 | outputStream.write(byteArray, 0, readCount)
73 | }
74 | }
75 | }
76 | } catch (e: IOException) {
77 | Log.e("wfeii", "$e")
78 | }
79 |
80 | }
81 |
82 | REQUEST_CODE_OPEN_FILE -> {
83 | val fileOutputStream =
84 | FileOutputStream(File(this.getExternalFilesDir(""), "11.jpg"))
85 | val inputStream = contentResolver.openInputStream(uri)
86 | val byteArray = ByteArray(1024)
87 | try {
88 | inputStream?.use {
89 | fileOutputStream.use {
90 | while (true) {
91 | val readCount = inputStream.read(byteArray)
92 | if (readCount == -1) {
93 | break
94 | }
95 | fileOutputStream.write(byteArray, 0, readCount)
96 | }
97 | }
98 | }
99 | } catch (e: IOException) {
100 |
101 | }
102 | }
103 | REQUEST_CODE_OPEN_FILE_TREE -> {
104 | val documentFile = DocumentFile.fromTreeUri(this, uri)
105 | if (documentFile != null) {
106 | Log.e(
107 | "wfeii",
108 | "documentFile : ${documentFile.name} ${documentFile.isDirectory}"
109 | )
110 | }
111 | }
112 | }
113 | }
114 |
115 | companion object {
116 | private val REQUEST_CODE_CREATE_FILE = 10
117 | private val REQUEST_CODE_OPEN_FILE = 20
118 | private val REQUEST_CODE_OPEN_FILE_TREE = 30
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/saf/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/saf/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/saf/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
26 |
27 |
35 |
36 |
--------------------------------------------------------------------------------
/saf/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/saf/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/saf/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/saf/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/saf/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/saf/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/saf/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/saf/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/saf/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/saf/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/saf/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/saf/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/saf/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/saf/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/saf/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/saf/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/saf/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/saf/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/saf/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/saf/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/saf/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wfeii/Android11/a52893bb41a7c12fbe4373392a34d3bc48b50caa/saf/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/saf/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 |
--------------------------------------------------------------------------------
/saf/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SAF
3 |
--------------------------------------------------------------------------------
/saf/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/saf/src/test/java/com/kuaima/saf/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.kuaima.saf
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':packagevisiblesecondapp'
2 | include ':packagevisibleoneapp'
3 | include ':saf'
4 | include ':manageexternalstorage'
5 | include ':destinationapp'
6 | include ':SourceApp'
7 | rootProject.name = "Android11"
--------------------------------------------------------------------------------