check for file storage permission before selecting avatar
This commit is contained in:
parent
5f63c397fa
commit
571eb2f7f9
|
@ -1,6 +1,5 @@
|
|||
package eu.siacs.conversations.ui;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ActionBar;
|
||||
import android.app.AlertDialog;
|
||||
|
@ -587,19 +586,6 @@ public class ConversationActivity extends XmppActivity
|
|||
}
|
||||
}
|
||||
|
||||
public boolean hasStoragePermission(int attachmentChoice) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, attachmentChoice);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
||||
if (grantResults.length > 0)
|
||||
|
@ -1359,7 +1345,7 @@ public class ConversationActivity extends XmppActivity
|
|||
}
|
||||
|
||||
private void openBatteryOptimizationDialogIfNeeded() {
|
||||
if (showBatteryOptimizationWarning() && getPreferences().getBoolean("show_battery_optimization", true)) {
|
||||
if (showBatteryOptimizationWarning() && getPreferences().getBoolean("show_battery_optimizationF", true)) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.battery_optimizations_enabled);
|
||||
builder.setMessage(R.string.battery_optimizations_enabled_dialog);
|
||||
|
|
|
@ -2,6 +2,7 @@ package eu.siacs.conversations.ui;
|
|||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
|
@ -136,16 +137,35 @@ public class PublishProfilePictureActivity extends XmppActivity {
|
|||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent attachFileIntent = new Intent();
|
||||
attachFileIntent.setType("image/*");
|
||||
attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
|
||||
Intent chooser = Intent.createChooser(attachFileIntent, getString(R.string.attach_file));
|
||||
startActivityForResult(chooser, REQUEST_CHOOSE_FILE);
|
||||
if (hasStoragePermission(REQUEST_CHOOSE_FILE)) {
|
||||
chooseAvatar();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
this.defaultUri = PhoneHelper.getSefliUri(getApplicationContext());
|
||||
}
|
||||
|
||||
private void chooseAvatar() {
|
||||
Intent attachFileIntent = new Intent();
|
||||
attachFileIntent.setType("image/*");
|
||||
attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
|
||||
Intent chooser = Intent.createChooser(attachFileIntent, getString(R.string.attach_file));
|
||||
startActivityForResult(chooser, REQUEST_CHOOSE_FILE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
||||
if (grantResults.length > 0)
|
||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
if (requestCode == REQUEST_CHOOSE_FILE) {
|
||||
chooseAvatar();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.siacs.conversations.ui;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.ActionBar;
|
||||
|
@ -793,6 +794,19 @@ public abstract class XmppActivity extends Activity {
|
|||
builder.create().show();
|
||||
}
|
||||
|
||||
public boolean hasStoragePermission(int requestCode) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, requestCode);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void selectPresence(final Conversation conversation,
|
||||
final OnPresenceSelected listener) {
|
||||
final Contact contact = conversation.getContact();
|
||||
|
|
Loading…
Reference in a new issue