Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 有人会告诉我如何获得远程通知吗?我的意思是,当服务器发布一些东西时,用户将获得通知_Java_Android - Fatal编程技术网

Java 有人会告诉我如何获得远程通知吗?我的意思是,当服务器发布一些东西时,用户将获得通知

Java 有人会告诉我如何获得远程通知吗?我的意思是,当服务器发布一些东西时,用户将获得通知,java,android,Java,Android,我搜索了很多,但我找到了一个基于通知管理器的代码,它 只是发生在用户点击时,我怎样才能在点击时以正确的方式进行 服务器上载用户收到通知的内容 public void shownotifications(View view) { NotificationCompat.Builder notificBuilder = new NotificationCompat.Builder(this); notificBuilder.setContentTitle("Title");

我搜索了很多,但我找到了一个基于通知管理器的代码,它 只是发生在用户点击时,我怎样才能在点击时以正确的方式进行 服务器上载用户收到通知的内容

   public void shownotifications(View view) {
    NotificationCompat.Builder notificBuilder = new NotificationCompat.Builder(this);
    notificBuilder.setContentTitle("Title");
    notificBuilder.setContentText("Message");
    notificBuilder.setTicker("Alert New Message");
    notificBuilder.setSmallIcon(R.drawable.icon);

    Intent moreInfoIntent = new Intent(this,MoreInfoNotification.class);
    TaskStackBuilder tStackBuilder = TaskStackBuilder.create(this);
    tStackBuilder.addParentStack(MoreInfoNotification.class);
    tStackBuilder.addNextIntent(moreInfoIntent);
    PendingIntent pendingIntent = tStackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
    notificBuilder.setContentIntent(pendingIntent);
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(notifID,notificBuilder.build());
    isNotificActive = true;

}

public void stopnotifications(View view) {

    if(isNotificActive){
        notificationManager.cancel(notifID);

    }
}

public void alertnotifications(View view) {

    Long alertTime = new GregorianCalendar().getTimeInMillis()+5*1000;
    Intent alertIntent = new Intent(this,AlertReceiver.class);
    AlarmManager alarmManager= (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP,alertTime,PendingIntent.getBroadcast(this,1,alertIntent,PendingIntent.FLAG_UPDATE_CURRENT));

}

您需要在服务器和设备上集成google
GCM
。 你可以通过。
这是谷歌的演示代码

还有一条建议,建议您在android手机上使用notification sdk推送通知。

我不知道,但这些可能会对您有所帮助。

我今天做了,但我不知道获取应用id和客户端密钥的正确方法