Search in sources :

Example 56 with Callback

use of com.codename1.util.Callback in project CodenameOne by codenameone.

the class PushNotificationService method push.

@Override
public void push(final String value) {
    final PushCallback callback = getPushCallbackInstance();
    if (callback != null) {
        Display.getInstance().callSerially(new Runnable() {

            public void run() {
                callback.push(value);
            }
        });
    } else {
        NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        Intent newIntent = new Intent(this, getStubClass());
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, newIntent, PendingIntent.FLAG_CANCEL_CURRENT);
        Notification.Builder builder = new Notification.Builder(this).setContentIntent(contentIntent).setSmallIcon(android.R.drawable.stat_notify_sync).setTicker(value).setAutoCancel(true).setWhen(System.currentTimeMillis()).setContentTitle(value).setDefaults(Notification.DEFAULT_ALL);
        Notification notif = builder.build();
        nm.notify((int) System.currentTimeMillis(), notif);
    }
}
Also used : NotificationManager(android.app.NotificationManager) PushCallback(com.codename1.push.PushCallback) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Aggregations

ActionListener (com.codename1.ui.events.ActionListener)14 ActionEvent (com.codename1.ui.events.ActionEvent)12 IOException (java.io.IOException)11 ConnectionRequest (com.codename1.io.ConnectionRequest)10 EventDispatcher (com.codename1.ui.util.EventDispatcher)8 NetworkEvent (com.codename1.io.NetworkEvent)6 InputStream (java.io.InputStream)5 Intent (android.content.Intent)4 ComponentAnimation (com.codename1.ui.animations.ComponentAnimation)4 ArrayList (java.util.ArrayList)4 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)3 Uri (android.net.Uri)3 IntentResultListener (com.codename1.impl.android.IntentResultListener)3 AccessToken (com.codename1.io.AccessToken)3 GZConnectionRequest (com.codename1.io.gzip.GZConnectionRequest)3 EncodedImage (com.codename1.ui.EncodedImage)3 Image (com.codename1.ui.Image)3 File (java.io.File)3 OutputStream (java.io.OutputStream)3 RandomAccessFile (java.io.RandomAccessFile)3