-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPermissionFile_im.java
74 lines (50 loc) · 2.19 KB
/
PermissionFile_im.java
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.example.ajit.imageupload.util;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Environment;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.ContextCompat;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Ajit on 05-10-2017.
*/
public class PermissionFile {
private Context mContext;
public PermissionFile( Context context) {
mContext = context;
}
public boolean checkLocStorgePermission(Context ctx) {
int readStorage = ContextCompat.checkSelfPermission(mContext,
Manifest.permission.READ_EXTERNAL_STORAGE);
int writeStorage = ContextCompat.checkSelfPermission(mContext,
Manifest.permission.WRITE_EXTERNAL_STORAGE);
int camera = ContextCompat.checkSelfPermission(mContext,
Manifest.permission.CAMERA);
List<String> listPermissionsNeeded = new ArrayList<>();
if (readStorage != PackageManager.PERMISSION_GRANTED && writeStorage != PackageManager.PERMISSION_GRANTED && camera != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
listPermissionsNeeded.add(Manifest.permission.READ_EXTERNAL_STORAGE);
listPermissionsNeeded.add(Manifest.permission.CAMERA);
}
if (Build.VERSION.SDK_INT >= 23) {
if (!listPermissionsNeeded.isEmpty()) {
ActivityCompat.requestPermissions((FragmentActivity) ctx,
listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]), Global.MULTI_LOC_STOR);
return false;
}
}
return true;
}
public File getFile() {
return new File(Environment.getExternalStorageDirectory() + File.separator + "SampleApp"
+ File.separator);
}
public String getUniqueImageFilename() {
return "img_" + System.currentTimeMillis() + ".png";
}
}