From a10c1647a9b941c34290d16a1636f02b955aea9d Mon Sep 17 00:00:00 2001 From: Durank Date: Tue, 15 Aug 2017 10:06:15 -0400 Subject: [PATCH] android_durank ---------------------------------------- 1-new method in LyfeCycleListener and AndroidNativeUtils to check the permission result --- .../impl/android/AndroidNativeUtil.java | 16 +++++++++++++--- .../impl/android/CodenameOneActivity.java | 9 +++++---- .../impl/android/LifecycleListener.java | 1 + 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Ports/Android/src/com/codename1/impl/android/AndroidNativeUtil.java b/Ports/Android/src/com/codename1/impl/android/AndroidNativeUtil.java index b260a308ff..3900a86537 100644 --- a/Ports/Android/src/com/codename1/impl/android/AndroidNativeUtil.java +++ b/Ports/Android/src/com/codename1/impl/android/AndroidNativeUtil.java @@ -29,9 +29,6 @@ import android.graphics.Canvas; import android.os.Bundle; import android.view.View; -import com.codename1.impl.android.AndroidImplementation; -import static com.codename1.impl.android.AndroidImplementation.checkForPermission; -import com.codename1.ui.Display; import java.util.ArrayList; import java.util.HashMap; @@ -207,4 +204,17 @@ public static interface BitmapViewRenderer { public static boolean checkForPermission(String permission, String description){ return AndroidImplementation.checkForPermission(permission, description, false); } + + /** + * @param requestCode to identify the permission requested + * @param permissionStatus true: if the user accept permission, false: if user denied the permission + */ + static void onRequestPermissionsResult(int requestCode,boolean permissionStatus) { + if(listeners != null) { + for(LifecycleListener l : listeners) { + l.onRequestPermissionsResult(requestCode,permissionStatus); + } + } + } + } diff --git a/Ports/Android/src/com/codename1/impl/android/CodenameOneActivity.java b/Ports/Android/src/com/codename1/impl/android/CodenameOneActivity.java index 706e05733b..b71492e604 100644 --- a/Ports/Android/src/com/codename1/impl/android/CodenameOneActivity.java +++ b/Ports/Android/src/com/codename1/impl/android/CodenameOneActivity.java @@ -35,7 +35,6 @@ import android.view.Menu; import android.view.MenuItem; import android.view.Window; -import android.widget.Toast; import com.codename1.payment.Product; import com.codename1.payment.PurchaseCallback; import com.codename1.payment.Receipt; @@ -705,7 +704,8 @@ public void setRequestForPermission(boolean requestForPermission) { public boolean isRequestForPermission() { return requestForPermission; } - + + @Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if(grantResults != null || grantResults.length == 0) { requestForPermission = false; @@ -713,9 +713,10 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in } if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { Log.i("Codename One", "PERMISSION_GRANTED"); + AndroidNativeUtil.onRequestPermissionsResult(requestCode, true); } else { - // Permission Denied - Toast.makeText(this, "Permission is denied", Toast.LENGTH_SHORT).show(); + AndroidNativeUtil.onRequestPermissionsResult(requestCode, false); + //Toast.makeText(this, "Permission is denied", Toast.LENGTH_SHORT).show(); } requestForPermission = false; } diff --git a/Ports/Android/src/com/codename1/impl/android/LifecycleListener.java b/Ports/Android/src/com/codename1/impl/android/LifecycleListener.java index 87f96bdd59..18fb9243b6 100644 --- a/Ports/Android/src/com/codename1/impl/android/LifecycleListener.java +++ b/Ports/Android/src/com/codename1/impl/android/LifecycleListener.java @@ -38,4 +38,5 @@ public interface LifecycleListener { public void onDestroy(); public void onSaveInstanceState(Bundle b); public void onLowMemory(); + public void onRequestPermissionsResult(int requestCode,boolean permissionStatus); }