Problem: I have a screenshot app that uses a floating overlay service for controls, and screen cast API Media Project Manager to get access to the screen. Sometimes when a d
I have a continues running service so i declared a one static variable inside the service and use it when user click my floating button (like chatheads).
public static Intent data = null; //declaration
then when first time user open the app I am asking for the permission and setting the value of the data in following way.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == 4){
Log.d(TAG, "onActivityResult: for Screen Capture");
if(resultCode == RESULT_OK)
{
Log.d(TAG, "onActivityResult: Permission Granted");
WindowChangeDetectingService.data = (Intent) data.clone();
screenCapturePermission = true;
updateUI();
}else
{
Log.d(TAG, "onActivityResult: Permission Deined");
screenCapturePermission = false;
updateUI();
SnackBar screenCapturePermissionSnackbar = new SnackBar(this, "This Permission is needed.", "Grant", new View.OnClickListener() {
@Override
public void onClick(View v) {
takeScreenCapturePermission();
}
});
screenCapturePermissionSnackbar.setDismissTimer(2000);
screenCapturePermissionSnackbar.show();
}
}
}
Finally when user clicks on the floating Overlay Button, first check value of the data.
if(WindowChangeDetectingService.data == null)
{
Log.d(TAG, "basicSetup: Asking permission again");
//open app again
}else
{
Log.d(TAG, "basicSetup: Getting permission for the object");
readPermissionObject();
}
Implementation of readPermissionObject is as follows
private void readPermissionObject()
{
Intent data = WindowChangeDetectingService.getData();
mMediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
startProjection(Activity.RESULT_OK,data);
}
Thanks to @netsplit for giving info about data.clone(); .