Skip to content

Commit 402a861

Browse files
committed
Update gradle, Add demo
1 parent 01a50d2 commit 402a861

File tree

6 files changed

+174
-4
lines changed

6 files changed

+174
-4
lines changed

.idea/codeStyles/Project.xml

Lines changed: 116 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.example.fileexplorer">
44

5+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
6+
57
<application
68
android:allowBackup="true"
79
android:icon="@mipmap/ic_launcher"
Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,62 @@
11
package com.example.fileexplorer;
22

3+
import android.Manifest;
34
import android.content.Intent;
4-
import android.support.v7.app.AppCompatActivity;
5+
import android.content.pm.PackageManager;
56
import android.os.Bundle;
7+
import android.support.annotation.NonNull;
8+
import android.support.annotation.Nullable;
9+
import android.support.v4.app.ActivityCompat;
10+
import android.support.v4.content.ContextCompat;
11+
import android.support.v7.app.AppCompatActivity;
12+
import android.widget.Toast;
613

714
import com.example.simplefileexplorer.SimpleFileExplorerActivity;
815

916
public class MainActivity extends AppCompatActivity {
1017

18+
private final String permission = Manifest.permission.WRITE_EXTERNAL_STORAGE;
19+
private final int file_explorer_request_result_code = 22;
20+
private final int permissions_request_code = 23;
21+
1122
@Override
1223
protected void onCreate(Bundle savedInstanceState) {
1324
super.onCreate(savedInstanceState);
1425
setContentView(R.layout.activity_main);
26+
27+
if (ContextCompat.checkSelfPermission(this, permission)
28+
!= PackageManager.PERMISSION_GRANTED) {
29+
ActivityCompat.requestPermissions(this,
30+
new String[]{this.permission},
31+
this.permissions_request_code);
32+
}
33+
else {
34+
this.startFileExplorerLibrary();
35+
}
36+
}
37+
38+
private void startFileExplorerLibrary(){
39+
Intent intent = new Intent(this, SimpleFileExplorerActivity.class);
40+
startActivityForResult(intent, file_explorer_request_result_code);
41+
}
42+
43+
@Override
44+
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
45+
if(requestCode == this.permissions_request_code){
46+
if(grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){
47+
this.startFileExplorerLibrary();
48+
}
49+
else{
50+
Toast.makeText(this, "Permission not granted.", Toast.LENGTH_LONG).show();
51+
}
52+
}
53+
}
54+
55+
@Override
56+
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
57+
if(data != null){
58+
String selectedAbsolutePath = data.getStringExtra(SimpleFileExplorerActivity.ON_ACTIVITY_RESULT_KEY);
59+
Toast.makeText(this, selectedAbsolutePath, Toast.LENGTH_SHORT).show();
60+
}
1561
}
1662
}

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77

88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.4.0'
10+
classpath 'com.android.tools.build:gradle:3.5.1'
1111

1212
// NOTE: Do not place your application dependencies here; they belong
1313
// in the individual module build.gradle files
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon May 06 10:20:29 EEST 2019
1+
#Sun Oct 13 13:31:45 EEST 2019
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

0 commit comments

Comments
 (0)