|
1 | 1 | package com.example.chatfull;
|
2 | 2 |
|
| 3 | +import android.Manifest; |
3 | 4 | import android.app.DownloadManager;
|
4 | 5 | import android.content.Context;
|
5 | 6 | import android.content.DialogInterface;
|
6 | 7 | import android.content.Intent;
|
7 | 8 | import android.content.SharedPreferences;
|
| 9 | +import android.content.pm.PackageManager; |
8 | 10 | import android.content.res.TypedArray;
|
9 | 11 | import android.database.Cursor;
|
10 | 12 | import android.graphics.Color;
|
11 | 13 | import android.net.Uri;
|
| 14 | +import android.os.Build; |
12 | 15 | import android.os.Bundle;
|
13 | 16 | import android.os.Environment;
|
14 | 17 | import android.os.Handler;
|
|
29 | 32 | import androidx.annotation.Nullable;
|
30 | 33 | import androidx.appcompat.app.AppCompatActivity;
|
31 | 34 | import androidx.appcompat.widget.Toolbar;
|
| 35 | +import androidx.core.app.ActivityCompat; |
32 | 36 |
|
33 | 37 | import com.bumptech.glide.Glide;
|
34 | 38 | import com.flask.colorpicker.ColorPickerView;
|
@@ -59,6 +63,7 @@ public class ChatActivity extends AppCompatActivity
|
59 | 63 | private static final int PICK_FILE_REQUEST = 1;
|
60 | 64 | private static final int PICK_IMAGE_REQUEST = 2;
|
61 | 65 | private static final byte CONTENT_TYPE_FILE = 1;
|
| 66 | + private static final int REQUEST_WRITE_EXTERNAL_STORAGE = 200; |
62 | 67 | private static String PREFERENCE_FILE_KEY;
|
63 | 68 | private final static String SHARED_PREFERENCES_KEY_MESSAGE_LIST = "User_Info_List";
|
64 | 69 | SharedPreferences sharedPref;
|
@@ -90,6 +95,7 @@ public class ChatActivity extends AppCompatActivity
|
90 | 95 | protected void onCreate(Bundle savedInstanceState) {
|
91 | 96 | super.onCreate(savedInstanceState);
|
92 | 97 | setContentView(R.layout.activity_chat_alternate);
|
| 98 | + isStoragePermissionGranted(); |
93 | 99 |
|
94 | 100 | user = (User) getIntent().getSerializableExtra("user");
|
95 | 101 |
|
@@ -164,6 +170,29 @@ public void loadImage(ImageView imageView, @Nullable String url, @Nullable Objec
|
164 | 170 | }
|
165 | 171 | }
|
166 | 172 |
|
| 173 | + public boolean isStoragePermissionGranted() { |
| 174 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
| 175 | + if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) |
| 176 | + == PackageManager.PERMISSION_GRANTED) { |
| 177 | + return true; |
| 178 | + } else { |
| 179 | + ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_WRITE_EXTERNAL_STORAGE ); |
| 180 | + return false; |
| 181 | + } |
| 182 | + } |
| 183 | + else { //permission is automatically granted on sdk<23 upon installation |
| 184 | + return true; |
| 185 | + } |
| 186 | + } |
| 187 | + |
| 188 | + @Override |
| 189 | + public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { |
| 190 | + super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
| 191 | + if(grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){ |
| 192 | + //resume tasks needing this permission |
| 193 | + } |
| 194 | + } |
| 195 | + |
167 | 196 | private void setClipboard(Context context, String text) {
|
168 | 197 | if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
|
169 | 198 | android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
0 commit comments