mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-30 22:34:02 +01:00 
			
		
		
		
	Request write permission for older android versions, too.
This commit is contained in:
		
							parent
							
								
									c8b0d2cee4
								
							
						
					
					
						commit
						1c50e8539b
					
				
					 1 changed files with 20 additions and 2 deletions
				
			
		|  | @ -1,7 +1,10 @@ | |||
| package fr.free.nrw.commons.contributions; | ||||
| 
 | ||||
| import android.app.Activity; | ||||
| import android.content.Context; | ||||
| import android.content.Intent; | ||||
| import android.content.pm.PackageManager; | ||||
| import android.content.pm.ResolveInfo; | ||||
| import android.net.Uri; | ||||
| import android.os.Bundle; | ||||
| import android.provider.MediaStore; | ||||
|  | @ -10,6 +13,7 @@ import android.support.v4.content.FileProvider; | |||
| 
 | ||||
| import java.io.File; | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
| 
 | ||||
| import fr.free.nrw.commons.upload.ShareActivity; | ||||
| import fr.free.nrw.commons.upload.UploadService; | ||||
|  | @ -41,14 +45,28 @@ public class ContributionController { | |||
|     } | ||||
| 
 | ||||
|     public void startCameraCapture() { | ||||
| 
 | ||||
|         Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | ||||
|         lastGeneratedCaptureUri = reGenerateImageCaptureUriInCache(); | ||||
|         takePictureIntent.setFlags( | ||||
|                 Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); | ||||
| 
 | ||||
|         // Intent.setFlags doesn't work for API level <20 | ||||
|         requestWritePermission(fragment.getContext(), takePictureIntent, lastGeneratedCaptureUri); | ||||
| 
 | ||||
|         takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, lastGeneratedCaptureUri); | ||||
|         fragment.startActivityForResult(takePictureIntent, SELECT_FROM_CAMERA); | ||||
|     } | ||||
| 
 | ||||
|     private static void requestWritePermission(Context context, Intent intent, Uri uri){ | ||||
| 
 | ||||
|         List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(intent, | ||||
|                 PackageManager.MATCH_DEFAULT_ONLY); | ||||
|         for (ResolveInfo resolveInfo : resInfoList) { | ||||
|             String packageName = resolveInfo.activityInfo.packageName; | ||||
|             context.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | | ||||
|                     Intent.FLAG_GRANT_READ_URI_PERMISSION); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public void startGalleryPick() { | ||||
|         //FIXME: Starts gallery (opens Google Photos) | ||||
|         Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Neslihan
						Neslihan