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

Jonas Czech
  • 12,018
  • 6
  • 44
  • 65
Dante
  • 465
  • 2
  • 12
  • 1
    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. – SubliemeSiem Jan 04 '16 at 12:36
  • I would recommemd you start a bounty on your question to make it more visible to people who can answer. – Jonas Czech Jan 04 '16 at 12:37
  • Thanks guys. I hope someone else can help me. – Dante Jan 10 '16 at 14:40
  • 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. – gkondati May 24 '18 at 20:41
  • 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 it – Roberth Solís Mar 03 '22 at 21:41

1 Answers1

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.