Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

150817 adding on request permission result #2182

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -705,17 +704,19 @@ 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;
return;
}
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}