mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 14:07:55 +01:00
Android: Ask permission to write files
This commit is contained in:
parent
0aacf20c16
commit
79ca54c5af
@ -76,11 +76,6 @@ public class DocumentViewActivity extends AppCompatActivity {
|
|||||||
*/
|
*/
|
||||||
public static final int REQUEST_CODE_ADD_FILE = 1;
|
public static final int REQUEST_CODE_ADD_FILE = 1;
|
||||||
|
|
||||||
/**
|
|
||||||
* Request code of editing document.
|
|
||||||
*/
|
|
||||||
public static final int REQUEST_CODE_EDIT_DOCUMENT = 2;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File view pager.
|
* File view pager.
|
||||||
*/
|
*/
|
||||||
@ -214,7 +209,7 @@ public class DocumentViewActivity extends AppCompatActivity {
|
|||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
Intent intent = new Intent(DocumentViewActivity.this, DocumentEditActivity.class);
|
Intent intent = new Intent(DocumentViewActivity.this, DocumentEditActivity.class);
|
||||||
intent.putExtra("document", DocumentViewActivity.this.document.toString());
|
intent.putExtra("document", DocumentViewActivity.this.document.toString());
|
||||||
startActivityForResult(intent, REQUEST_CODE_EDIT_DOCUMENT);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
package com.sismics.docs.util;
|
package com.sismics.docs.util;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.DownloadManager;
|
import android.app.DownloadManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.support.v4.app.ActivityCompat;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for network actions.
|
* Utility class for network actions.
|
||||||
@ -19,9 +24,14 @@ public class NetworkUtil {
|
|||||||
* @param title Notification title
|
* @param title Notification title
|
||||||
* @param description Notification description
|
* @param description Notification description
|
||||||
*/
|
*/
|
||||||
public static void downloadFile(Context context, String url, String fileName, String title, String description) {
|
public static void downloadFile(Activity activity, String url, String fileName, String title, String description) {
|
||||||
String authToken = PreferenceUtil.getAuthToken(context);
|
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||||
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String authToken = PreferenceUtil.getAuthToken(activity);
|
||||||
|
DownloadManager downloadManager = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE);
|
||||||
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
||||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
|
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
|
||||||
|
Loading…
Reference in New Issue
Block a user