Reputation: 989
I'm trying to implement askForPermisions
function as an Adobe Native Extension (ANE) for AIR. My function is now defined as:
public class APKaskForPermission implements FREFunction {
public static final String TAG = "askForPermission";
@Override
public FREObject call(FREContext ctx, FREObject[] passedArgs) {
FREObject result = null;
String permission;
Integer requestCode;
try{
permission = passedArgs[0].getAsString();
requestCode = passedArgs[1].getAsInt();
if (ContextCompat.checkSelfPermission(NativeExtension.appContext, permission) != PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(ctx.getActivity(), permission)) {
Log.d(TAG, "shouldShowRequestPermissionRationale: " + permission);
//This is called if user has denied the permission before
//In this case I am just asking the permission again
Log.d(TAG, "requestPermissions: " + permission);
ActivityCompat.requestPermissions(ctx.getActivity(), new String[]{permission}, requestCode);
} else {
Log.d(TAG, "requestPermissions: " + permission);
ActivityCompat.requestPermissions(ctx.getActivity(), new String[]{permission}, requestCode);
}
result = FREObject.newObject(false);
} else {
Log.d(TAG, "" + permission + " is already granted.");
//Toast.makeText(this, "" + permission + " is already granted.", Toast.LENGTH_SHORT).show();
result = FREObject.newObject(true);
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
return result;
}
}
This display the dialog as expected, but I cannot find what to do to get the response, as all examples on the web define it in the MainActivity source, but I'm in the native extension context.
Any help?
Upvotes: 0
Views: 644
Reputation: 989
As Wadedwalker mention in this discussion, it is not possible to override or add methods at runtime to another class, in this case main AIR app activity. So probably the best way is to launch a new blank Activity for the purpose of triggering the popup and so be able to wait for the onRequestPermissionsResult() response.
I managed to get own working basic ANE version, which is opensourced here: https://github.com/Oldes/ANEAmanitaAndroid-public/tree/eclipse-permissions
Upvotes: 0