Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Titanium GCM service to catch notifications

$
0
0

Hello, For two days I go to a lot of trouble on receiving notifications when my application is not open. To do this I created a service that verifies every 3000 milliseconds if there are notifications.

var CloudPush = require('ti.cloudpush');
CloudPush.addEventListener('callback', function (evt) {
    var activity = Ti.Android.currentActivity;
    var intent = Ti.Android.createIntent({
        action : Ti.Android.ACTION_MAIN,
        className: 'fr.faceperso.Face2facesActivity',
        flags : Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Ti.Android.FLAG_ACTIVITY_SINGLE_TOP
    });
    intent.addCategory(Titanium.Android.CATEGORY_LAUNCHER);
 
    var pending = Ti.Android.createPendingIntent({
        activity : activity,
        intent : intent,
        type : Ti.Android.PENDING_INTENT_FOR_ACTIVITY,
        flags : Ti.Android.FLAG_ACTIVITY_NO_HISTORY
    });
 
    //var message = "Time is up!";
 
    var notificationOptions = {
        contentIntent : pending,
        contentTitle : 'Title notif',
        contentText : 'Message notif',
        tickerText : '',
        icon : Ti.App.Android.R.drawable.appicon,
        flags : Titanium.Android.FLAG_AUTO_CANCEL | Titanium.Android.FLAG_SHOW_LIGHTS | Titanium.Android.FLAG_INSISTENT,
        sound : Titanium.Android.NotificationManager.DEFAULT_SOUND
    };
 
    var notification = Ti.Android.createNotification(notificationOptions);
    Ti.Android.NotificationManager.notify(1, notification);
    Ti.App.Properties.setBool("service_running", true);
 
    Ti.Media.vibrate([0, 100, 100, 200, 100, 100, 200, 100, 100, 200]);
 
});
I think the problem comes from the fact that the service level I have no access to the module ti.cloudpush ! How I could do to catch notifications at my service. Thank you in advance for your reply

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>