Java 在设备顶栏上本地显示推送通知
我想将我的android应用注册到基于位置的推送通知 我这里没有什么好的建议 这里有很好的建筑理念 如果我理解正确,我没有必要使用GCM,而是使用我自己的服务器。对吧?Java 在设备顶栏上本地显示推送通知,java,android,push-notification,location,Java,Android,Push Notification,Location,我想将我的android应用注册到基于位置的推送通知 我这里没有什么好的建议 这里有很好的建筑理念 如果我理解正确,我没有必要使用GCM,而是使用我自己的服务器。对吧? 在我将我的位置推送到服务器并获得JSON响应后-如何在设备顶部栏上本地显示它?创建一个接收器,在其接收到消息时触发通知。 您可以使用以下代码创建通知: import android.app.Notification; import android.app.NotificationManager; impo
在我将我的位置推送到服务器并获得JSON响应后-如何在设备顶部栏上本地显示它?创建一个接收器,在其接收到消息时触发通知。 您可以使用以下代码创建通知:
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());
}
顺便说一句,接收者将如何从服务器获取消息?我应该将其注册到哪个事件\意图?