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;
|
package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
import android.Manifest;
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.ActionBar;
|
import android.app.ActionBar;
|
||||||
import android.app.AlertDialog;
|
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
|
@Override
|
||||||
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
||||||
if (grantResults.length > 0)
|
if (grantResults.length > 0)
|
||||||
|
@ -1359,7 +1345,7 @@ public class ConversationActivity extends XmppActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openBatteryOptimizationDialogIfNeeded() {
|
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);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setTitle(R.string.battery_optimizations_enabled);
|
builder.setTitle(R.string.battery_optimizations_enabled);
|
||||||
builder.setMessage(R.string.battery_optimizations_enabled_dialog);
|
builder.setMessage(R.string.battery_optimizations_enabled_dialog);
|
||||||
|
|
|
@ -2,6 +2,7 @@ package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
@ -136,14 +137,33 @@ public class PublishProfilePictureActivity extends XmppActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
if (hasStoragePermission(REQUEST_CHOOSE_FILE)) {
|
||||||
|
chooseAvatar();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.defaultUri = PhoneHelper.getSefliUri(getApplicationContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void chooseAvatar() {
|
||||||
Intent attachFileIntent = new Intent();
|
Intent attachFileIntent = new Intent();
|
||||||
attachFileIntent.setType("image/*");
|
attachFileIntent.setType("image/*");
|
||||||
attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
|
attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
|
||||||
Intent chooser = Intent.createChooser(attachFileIntent, getString(R.string.attach_file));
|
Intent chooser = Intent.createChooser(attachFileIntent, getString(R.string.attach_file));
|
||||||
startActivityForResult(chooser, REQUEST_CHOOSE_FILE);
|
startActivityForResult(chooser, REQUEST_CHOOSE_FILE);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
this.defaultUri = PhoneHelper.getSefliUri(getApplicationContext());
|
@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
|
@Override
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.siacs.conversations.ui;
|
package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.ActionBar;
|
import android.app.ActionBar;
|
||||||
|
@ -793,6 +794,19 @@ public abstract class XmppActivity extends Activity {
|
||||||
builder.create().show();
|
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,
|
public void selectPresence(final Conversation conversation,
|
||||||
final OnPresenceSelected listener) {
|
final OnPresenceSelected listener) {
|
||||||
final Contact contact = conversation.getContact();
|
final Contact contact = conversation.getContact();
|
||||||
|
|
Loading…
Reference in a new issue