Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show the Google Location Services permission request dialog above / through the lockscreen?

I'm trying to show the Google Location Services (turn on GPS, network data, etc.) Dialog through lock screen.

I'm using KeyguardManager to disable Lock screen. This works fine as my MainActivity is able to disable the lock screen. However, as soon as the Google Location Services Dialog shows up, the lock screen is back to enable, the screen is locked and I can't get to my MainActivity unless I unlock the screen.

I've even tried ...Flag_Show_When_Locked, but it didn't help.

Here is my code:

private KeyguardLock DisableScreenLock; 

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

    setContentView(R.main_layout);


    KeyguardManager myKeyGuard = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
    DisableScreenLock = myKeyGuard.newKeyguardLock("disableKeyguard");
    DisableScreenLock.disableKeyguard();
}


protected synchronized void GoogleApiClient_Intialize() {
    Log.e(TAG, "Building GoogleApiClient");
    googleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();
}
protected void LocationRequest_Intialize() {
    locationRequest = new LocationRequest();
    locationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
    locationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}

protected void LocationSettingsRequest_Builder() {
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
    builder.addLocationRequest(locationRequest);
    locationSettingsRequest = builder.build();
}
@Override
public void onConnected(Bundle connectionHint) {
    Log.e(TAG, "GoogleApiClient is connected");
    LocationSettings_Check_Start();  
}
protected void LocationSettings_Check_Start() {
    PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(
                                                            googleApiClient, locationSettingsRequest);
    result.setResultCallback(this);
}

Is there anyway I can show this Google Location Services Dialog through password/pattern/pin, etc.. lock screen?

Thank you very much for your help.

enter image description here

like image 329
Dante Avatar asked Nov 21 '15 20:11

Dante


1 Answers

Unfortunately this is not possible, because the dialog you want to show is contained in an Activity that does not belong to your app.

This means that can neither get a reference to this Activity, or invoke methods on it, nor, nor override any of its properties with AndroidManifest.xml.

To be certain that this is indeed not possible, I added an ActivityLifecycleListener in the Application.onCreate() of one of my apps which uses Google Location Services and asks for a similar permission, in order to get a reference to this Activity.

In the ActivityLifecycleListener.onResume() I added some logging code, and noticed that even when the Google Play Services dialog was showing on the screen nothing was logged, however the log worked as expected for the Activities that were on the manifest file. Also, to see the app with Logcat in Android Studio, I have to set the Logcat filter to "No filters", which means that my app cannot reference this Activity in any way.

like image 103
Leo supports Monica Cellio Avatar answered Sep 28 '22 02:09

Leo supports Monica Cellio