Skip to content

Commit

Permalink
feat(android): Support android target api 30 (#1673)
Browse files Browse the repository at this point in the history
  • Loading branch information
ravirajn22 committed Apr 28, 2021
1 parent 092cbd7 commit b0ea537
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
25 changes: 13 additions & 12 deletions android/src/main/java/com/imagepicker/ImagePickerModule.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.imagepicker;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
Expand Down Expand Up @@ -101,12 +102,12 @@ public void launchCamera(final ReadableMap options, final Callback callback) {
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, cameraCaptureURI);
cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

if (cameraIntent.resolveActivity(reactContext.getPackageManager()) == null) {
callback.invoke(getErrorMap(errOthers, "Activity error"));
return;
try {
currentActivity.startActivityForResult(cameraIntent, requestCode);
} catch (ActivityNotFoundException e) {
callback.invoke(getErrorMap(errOthers, e.getMessage()));
this.callback = null;
}

currentActivity.startActivityForResult(cameraIntent, requestCode);
}

@ReactMethod
Expand All @@ -131,13 +132,12 @@ public void launchImageLibrary(final ReadableMap options, final Callback callbac
libraryIntent = new Intent(Intent.ACTION_PICK);
libraryIntent.setType("image/*");
}

if (libraryIntent.resolveActivity(reactContext.getPackageManager()) == null) {
callback.invoke(getErrorMap(errOthers, "Activity error"));
return;
try {
currentActivity.startActivityForResult(Intent.createChooser(libraryIntent, null), requestCode);
} catch (ActivityNotFoundException e) {
callback.invoke(getErrorMap(errOthers, e.getMessage()));
this.callback = null;
}

currentActivity.startActivityForResult(Intent.createChooser(libraryIntent, null), requestCode);
}

void onImageObtained(Uri uri) {
Expand All @@ -152,7 +152,8 @@ void onVideoObtained(Uri uri) {
@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {

if (!isValidRequestCode(requestCode)) {
// onActivityResult is called even when ActivityNotFoundException occurs
if (!isValidRequestCode(requestCode) || (this.callback == null)) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ buildscript {
ext {
buildToolsVersion = "29.0.2"
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 28
compileSdkVersion = 30
targetSdkVersion = 30
}
repositories {
google()
Expand Down

0 comments on commit b0ea537

Please sign in to comment.