Mukesh Kumar
Mukesh Kumar

Reputation: 131

How to continuously active Internet on doze mode Marshmallow and Nougat

I'm working on real-time location tracking app and updating current location to the server via using foreground service.

Now i'm able to keep app active while device in deep sleep. But due to Network access is suspended on Doze mode, i can't able to update it on server.
As per google developer guide suggestion we can solve this issue by using high-priority FCM messages. But in my case how to notify server for push notification while Network access is suspended (need to identify internet access disable either by OS or manually).

Upvotes: 8

Views: 1182

Answers (2)

Rupali
Rupali

Reputation: 774

One way is register for action-

"android.os.action.DEVICE_IDLE_MODE_CHANGED" 

this will broadcast once the device modes will change and then figure out device is in doze/non-doze using :

PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);

boolean isDeviceIdle = pm.isDeviceIdleMode();

Upvotes: 2

nAkhmedov
nAkhmedov

Reputation: 3592

Try to check NetworkInfo status

public static boolean isNetBlocked(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();

    return networkInfo != null && networkInfo.getDetailedState().name().equals(NetworkInfo.DetailedState.BLOCKED.name());
}

Upvotes: 0

Related Questions