How to wake up the phone remotely?

I want to create an Android application that needs to be launched remotely via 3G (after receiving a push notification via a socket).

I did some research, and it seems to get very complex as soon as the screen turns off, and also because Android kills idle sockets.

Is there an example project demonstrating how to implement this reliably? I found the WakefulIntentService library, but it does not take into account that the socket should be saved.

An alternative would be to periodically poll a specific URL for the wake-up signal, but this will lead to a long delay before the device detects that it needs to start the application, depending on the polling interval.

+4
source share
2 answers

Have you viewed GCM or parse.com to send and receive a click?

I don’t think they are easy to kill.

If you have not said that your socket is working in the service. Then it can work in the background regardless of active activity and start when the device boots up. In addition, this will reduce the likelihood that Android will disconnect.

+2
source
public abstract class WakeLocker {
    private static PowerManager.WakeLock wakeLock;

    public static void acquire(Context context) {
        if (wakeLock != null) wakeLock.release();

        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |
                PowerManager.ACQUIRE_CAUSES_WAKEUP |
                PowerManager.ON_AFTER_RELEASE, "WakeLock");
        wakeLock.acquire();
    }

    public static void release() {
        if (wakeLock != null) wakeLock.release(); wakeLock = null;
    }
}

In the manifest, add this line:

<uses-permission android:name="android.permission.WAKE_LOCK" />

If you want to wake up, use:

WakeLocker.acquire(this);

after the call is completed

WakeLocker.release();
0
source

Source: https://habr.com/ru/post/1527602/


All Articles