mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Merge pull request #188 from misaochan/master
Fix gallery issue for Android M
This commit is contained in:
commit
27f9245acf
3 changed files with 38 additions and 5 deletions
|
|
@ -85,7 +85,6 @@ public class ContributionController {
|
|||
try {
|
||||
activity.startActivity(shareIntent);
|
||||
} catch (SecurityException e) {
|
||||
//FIXME: Add permission request here. Only startActivity if permission has been granted.
|
||||
Log.e("ContributionController", "Security Exception", e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
package fr.free.nrw.commons.contributions;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
|
@ -94,8 +99,20 @@ public class ContributionsListFragment extends Fragment {
|
|||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch(item.getItemId()) {
|
||||
case R.id.menu_from_gallery:
|
||||
//Gallery crashes before reach ShareActivity screen so must implement permissions check here
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (ContextCompat.checkSelfPermission(this.getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this.getActivity(), new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
|
||||
return true;
|
||||
} else {
|
||||
controller.startGalleryPick();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
controller.startGalleryPick();
|
||||
return true;
|
||||
}
|
||||
case R.id.menu_from_camera:
|
||||
controller.startCameraCapture();
|
||||
return true;
|
||||
|
|
@ -129,6 +146,23 @@ public class ContributionsListFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode,
|
||||
String permissions[], int[] grantResults) {
|
||||
switch (requestCode) {
|
||||
// 1 = Storage allowed when gallery selected
|
||||
case 1: {
|
||||
if (grantResults.length > 0
|
||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
controller.startGalleryPick();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
menu.clear(); // See http://stackoverflow.com/a/8495697/17865
|
||||
|
|
|
|||
|
|
@ -150,8 +150,8 @@
|
|||
<string name="provider_campaigns">Campaigns</string>
|
||||
<string name="menu_refresh">Refresh</string>
|
||||
|
||||
<string name="storage_permission_rationale">Required: Read external storage. App cannot function without this.</string>
|
||||
<string name="location_permission_rationale">Optional: Current location for category suggestions</string>
|
||||
<string name="storage_permission_rationale">Required permission: Read external storage. App cannot function without this.</string>
|
||||
<string name="location_permission_rationale">Optional permission: Get current location for category suggestions</string>
|
||||
<string name="ok">OK</string>
|
||||
<string name="back">Back</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue