Put the permission request when clicking to the button to choose a picture.
This commit is contained in:
parent
2e3839cbe0
commit
e90b33e188
|
@ -118,7 +118,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
private RelativeLayout main_app_container;
|
private RelativeLayout main_app_container;
|
||||||
private Stack<Integer> stackBack = new Stack<>();
|
private Stack<Integer> stackBack = new Stack<>();
|
||||||
|
|
||||||
private final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 0;
|
|
||||||
|
|
||||||
public MainActivity() {
|
public MainActivity() {
|
||||||
}
|
}
|
||||||
|
@ -444,40 +444,10 @@ public class MainActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
Helper.switchLayout(MainActivity.this);
|
Helper.switchLayout(MainActivity.this);
|
||||||
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
|
||||||
|
|
||||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
|
|
||||||
PackageManager.PERMISSION_GRANTED) {
|
|
||||||
// Should we show an explanation?
|
|
||||||
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
|
|
||||||
Manifest.permission.READ_EXTERNAL_STORAGE)) {
|
|
||||||
|
|
||||||
// If we want to explain the reason for the permission it needs to be added here.
|
|
||||||
|
|
||||||
} else {
|
|
||||||
ActivityCompat.requestPermissions(this,
|
|
||||||
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
|
|
||||||
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRequestPermissionsResult(int requestCode,
|
|
||||||
String permissions[], int[] grantResults) {
|
|
||||||
switch (requestCode) {
|
|
||||||
case MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE: {
|
|
||||||
// If request is cancelled, the result arrays are empty.
|
|
||||||
if (grantResults.length > 0
|
|
||||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
||||||
// We have the permission.
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -14,7 +14,11 @@
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
package fr.gouv.etalab.mastodon.activities;
|
package fr.gouv.etalab.mastodon.activities;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
|
@ -144,6 +148,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
||||||
private HorizontalScrollView picture_scrollview;
|
private HorizontalScrollView picture_scrollview;
|
||||||
private int currentCursorPosition, searchLength;
|
private int currentCursorPosition, searchLength;
|
||||||
private TextView toot_space_left;
|
private TextView toot_space_left;
|
||||||
|
private final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 754;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -303,10 +308,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
||||||
int charsInCw = 0;
|
int charsInCw = 0;
|
||||||
int charsInToot = 0;
|
int charsInToot = 0;
|
||||||
|
|
||||||
// TODO: Sort out multiple images
|
uploadSharedImage(sharedUri);
|
||||||
if (sharedUri != null) {
|
|
||||||
uploadSharedImage(sharedUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isAccountPrivate = account.isLocked();
|
boolean isAccountPrivate = account.isLocked();
|
||||||
if(isAccountPrivate){
|
if(isAccountPrivate){
|
||||||
|
@ -411,6 +413,23 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
|
|
||||||
|
if (ContextCompat.checkSelfPermission(TootActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
|
||||||
|
PackageManager.PERMISSION_GRANTED) {
|
||||||
|
// Should we show an explanation?
|
||||||
|
if (ActivityCompat.shouldShowRequestPermissionRationale(TootActivity.this,
|
||||||
|
Manifest.permission.READ_EXTERNAL_STORAGE)) {
|
||||||
|
// If we want to explain the reason for the permission it needs to be added here.
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ActivityCompat.requestPermissions(TootActivity.this,
|
||||||
|
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
|
||||||
|
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Intent intent;
|
Intent intent;
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
|
||||||
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||||
|
@ -511,7 +530,21 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode,
|
||||||
|
@NonNull String permissions[], @NonNull int[] grantResults) {
|
||||||
|
switch (requestCode) {
|
||||||
|
case MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE: {
|
||||||
|
// If request is cancelled, the result arrays are empty.
|
||||||
|
if (grantResults.length > 0
|
||||||
|
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
// We have the permission.
|
||||||
|
toot_picture.callOnClick();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
public void showAToast (String message){
|
public void showAToast (String message){
|
||||||
if (mToast != null) {
|
if (mToast != null) {
|
||||||
mToast.cancel();
|
mToast.cancel();
|
||||||
|
|
Loading…
Reference in New Issue