RSS

Monthly Archives: September 2017

Android Push Notifications when app is closed

By: Charuක

 

Yes, it is possible ‘to receive notifications from google cloud message when the application is fully closed’.

Infact, A broadcast receiver is the mechanism GCM uses to deliver messages. You need to have implement a BroadcastReceiver and declare it in the AndroidManifest.xml.

Please refer to the following code snippet.

AndroidManifest.xml

<receiver
    android:name=".GcmBroadcastReceiver"
    android:permission="com.google.android.c2dm.permission.SEND" >
    <intent-filter>
        <!-- Receives the actual messages. -->
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <category android:name="com.google.android.gcm.demo.app" />
    </intent-filter>
</receiver>
<service android:name=".GcmIntentService" />

Java code

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        // Explicitly specify that GcmIntentService will handle the intent.
        ComponentName comp = new ComponentName(context.getPackageName(),
                GcmIntentService.class.getName());
        // Start the service, keeping the device awake while it is launching.
        startWakefulService(context, (intent.setComponent(comp)));
        setResultCode(Activity.RESULT_OK);
    }
}

When GCM delivers a message to your device, BroadcastReceiver will receive the message and call the onReceive() function, wherein you may start a service to actually perform the intended task for you.

The above Code example uses a specialized BroadcastReceiver called WakefulBroadcastReceiver, which makes sure that the device doesn’t go to sleep, while the service is doing its work.

Refer to the Official Android Page for the same: https://developer.android.com/google/gcm/client.html

 

 

 

Copy from: https://stackoverflow.com/questions/24313539/push-notifications-when-app-is-closed

Advertisements
 
Leave a comment

Posted by on September 15, 2017 in Android, Mobile Development

 

Auto start pm2 when reboot Windows

install pm2:

$ npm install pm2 -g

install mp2 start for windows

$ npm install pm2-windows-startup -g

 

install pm2 window service

$ npm i pm2-windows-service -g

$ pm2-service-install [-n <service name>]

and go to this install path: C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2-windows-service\src\daemon\ and find file

is called “mp2node” and edit at <argument>[js file].js</argument> to path of your javascript file and save and reboot service in “Service.msc”

 

 

 

 

 
Leave a comment

Posted by on September 7, 2017 in NodeJs, pm2