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

1

10

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

Nation answered 21/11, 2015 at 20:0 Comment(5)
I'm not sure, but I think this is not possible, since the device needs to be unlocked to access the settings, which is basically what is happening here.Centri
I would recommemd you start a bounty on your question to make it more visible to people who can answer.Bettis
Thanks guys. I hope someone else can help me.Nation
I think its not possible to display any dialog on lock screen, but you can fake it buy using Notification, once user selects the notification then display location permission.Isodiametric
I have that bug, that is possible, I need remove the permission notification from the lock screen, to be honest I'm not sure How I did itMegathere
F
3

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.

Fusee answered 22/5, 2018 at 20:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.