简体   繁体   中英

presenting push notifications locally on the device topbar

I want to register my android app to location based push notifications.

I got few great tips here

and nice architecture idea here.

If I understand correctly, I have no point using GCM - but rather use my own server. right?

After I push my location to the server and get a JSON response - how do i present it locally on my device top bar?

Create a receiver to trigger the notification when its receives a message. you can create notification using these codes:

    import android.app.Notification;
    import android.app.NotificationManager;
    import android.app.PendingIntent;

    private NotificationManager mNotificationManager;
    NotificationCompat.Builder builder;
    Context ctx;
    private  void sendNotification(Intent receivedIntent) {

      mNotificationManager = (NotificationManager)ctx.getSystemService(Context.NOTIFICATION_SERVICE);
      Intent intent = new Intent(ctx, ReceiveNotification.class);// this will open the class receiveNotification when the notification is clicked
      intent.putExtra("author", receivedIntent.getStringExtra("author"));

      PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 0, intent , 0);
      NotificationCompat.Builder noti =  new NotificationCompat.Builder(ctx)
       .setSmallIcon(R.drawable.ic_launcher)     // if you want to include an icon
       .setContentTitle("your app name")
       .setStyle(new NotificationCompat.BigTextStyle()
       .bigText("By: " +  receivedIntent.getStringExtra("name")))
       .setWhen(System.currentTimeMillis())
       .setTicker("By: " +  receivedIntent.getStringExtra("name"))
       .setDefaults(Notification.DEFAULT_SOUND)
       .setContentText("your message");
       noti.setContentIntent(pendingIntent);
        mNotificationManager.notify(1, noti.build());

   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM