Skip to content

Commit

Permalink
Read external storage permission on file attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
AgiMaulana committed Mar 22, 2018
1 parent d14e996 commit 8b8ee42
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
1 change: 1 addition & 0 deletions omniNotes/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission android:name="com.google.android.apps.photos.permission.GOOGLE_PHOTOS" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@
import android.os.Bundle;
import android.os.Handler;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v4.util.Pair;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.widget.DrawerLayout;
Expand Down Expand Up @@ -125,6 +128,7 @@ public class DetailFragment extends BaseFragment implements OnReminderPickedList
private static final int CATEGORY = 5;
private static final int DETAIL = 6;
private static final int FILES = 7;
private final int RC_READ_EXTERNAL_STORAGE_PERMISSION = 1;

@BindView(R.id.detail_root)
ViewGroup root;
Expand Down Expand Up @@ -1499,6 +1503,17 @@ private void onActivityResultManageReceivedFiles(Intent intent) {
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if(requestCode == RC_READ_EXTERNAL_STORAGE_PERMISSION){
if(grantResults.length > 1 && permissions[0] == Manifest.permission.READ_EXTERNAL_STORAGE){

}else{

}
}
}

/**
* Discards changes done to the note and eventually delete new attachments
Expand Down Expand Up @@ -2333,6 +2348,7 @@ private class AttachmentOnClickListener implements OnClickListener {

@Override
public void onClick(View v) {

switch (v.getId()) {
// Photo from camera
case R.id.camera:
Expand All @@ -2358,12 +2374,12 @@ public void onClick(View v) {
attachmentDialog.dismiss();
break;
case R.id.files:
Intent filesIntent;
filesIntent = new Intent(Intent.ACTION_GET_CONTENT);
filesIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
filesIntent.addCategory(Intent.CATEGORY_OPENABLE);
filesIntent.setType("*/*");
startActivityForResult(filesIntent, FILES);
if (ContextCompat.checkSelfPermission(getActivity(),
Manifest.permission.READ_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED)
startGetContentAction();
else
askReadExternalStoragePermission();
attachmentDialog.dismiss();
break;
case R.id.sketch:
Expand All @@ -2388,6 +2404,21 @@ public void onClick(View v) {
}
}

public void startGetContentAction() {
Intent filesIntent;
filesIntent = new Intent(Intent.ACTION_GET_CONTENT);
filesIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
filesIntent.addCategory(Intent.CATEGORY_OPENABLE);
filesIntent.setType("*/*");
startActivityForResult(filesIntent, FILES);
}

private void askReadExternalStoragePermission(){
PermissionsHelper.requestPermission(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE,
R.string.permission_audio_recording,
snackBarPlaceholder, () -> startGetContentAction());
}


public void onEventMainThread(PushbulletReplyEvent pushbulletReplyEvent) {
content.setText(getNoteContent() + System.getProperty("line.separator") + pushbulletReplyEvent.message);
Expand Down
1 change: 1 addition & 0 deletions omniNotes/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
<string name="filter_archived">Hide archived notes</string>
<string name="remove_filter_archived">Show archived notes</string>
<string name="permission_external_storage">Permission to write on external storage is needed to allow backups on public folders</string>
<string name="permission_external_storage_detail_attachment">Permission to write on external storage is needed to allow read content from public folders</string>
<string name="permission_audio_recording">Permission to use microphone is needed to record audio notes</string>
<string name="permission_coarse_location">Permission to access to location is needed to add position informations to your notes</string>
<string name="permission_not_granted">Permission not granted</string>
Expand Down

0 comments on commit 8b8ee42

Please sign in to comment.