Android如何使用Drupal服务器接收推送通知

安卓

我按照教程中的所有步骤进行操作。教程android推送通知

Drupal服务器端工作链接

通过使用GCM ID,我的设备已在drupal服务器上成功注册。

我的问题是,从服务器发送推送通知时,它显示“成功发送通知”,但是此通知未在电话上收到。

谁能建议我该怎么办....

安卓

终于我发现了我的错误。

我正在尝试在广播接收器中获取通知消息,但是我在此服务onMessage(Context context,Intent data)中获取消息是错误的。

public class GCMIntentService extends GCMBaseIntentService{

private static final String TAG = "GCMIntentService";

public GCMIntentService() {
    super(SENDER_ID);
}

@Override
protected void onError(Context arg0, String arg1) {
    // TODO Auto-generated method stub

}

@Override
protected void onMessage(Context context, Intent data) {

    Log.i(TAG, "new message= ");
      String message = data.getExtras().getString("message");
      /*if (message.equals("") ) {
          //message="hellow senha , this is vc circle notification. You can check how it display long or short...";
          generateNotification(context, message);   
      }else{
          generateNotification(context, message);   
      }*/
      //message="hellow senha , this is vc circle notification. You can check how it display long or short...";
      generateNotification(context, message);   
}

private void generateNotification(Context context, String message) {

    int icon = R.drawable.vc_placeholder;
      long when = System.currentTimeMillis();
      NotificationManager notificationManager = (NotificationManager) context
        .getSystemService(Context.NOTIFICATION_SERVICE);

      Intent notificationIntent = new Intent(context, SplashScreenActivity.class);
      notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
        | Intent.FLAG_ACTIVITY_SINGLE_TOP);
      PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0,
        notificationIntent, 0);

      NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                context);

      Notification notification = mBuilder.setSmallIcon(icon).setTicker("VCCircle").setWhen(when)
                .setContentTitle(context.getString(R.string.app_name))
                .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                .setContentIntent(resultPendingIntent)
                .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.vc_placeholder))
                .setContentText(message).build();

     notification.flags |= Notification.FLAG_AUTO_CANCEL;
      notificationManager.notify(0, notification);

      {
            // Wake Android Device when notification received
            PowerManager pm = (PowerManager) context
                    .getSystemService(Context.POWER_SERVICE);
            final PowerManager.WakeLock mWakelock = pm.newWakeLock(
                    PowerManager.FULL_WAKE_LOCK
                            | PowerManager.ACQUIRE_CAUSES_WAKEUP, "GCM_PUSH");
            mWakelock.acquire();

            // Timer before putting Android Device to sleep mode.
            Timer timer = new Timer();
            TimerTask task = new TimerTask() {
                public void run() {
                    mWakelock.release();
                }
            };
            timer.schedule(task, 5000);
        }



}

@Override
protected void onRegistered(Context context, String registrationId) {
    Log.i(TAG, "Device registered: regId = " + registrationId);
    displayMessage(context, getString(R.string.gcm_registered));
    boolean te=ServerUtilities.register(context, registrationId);
    System.out.println("Device Register : "+te);
}

@Override
protected void onUnregistered(Context arg0, String arg1) {
    // TODO Auto-generated method stub

}

}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如果从我们的服务器推送,Android Parse Notification无法接收通知

来自分类Dev

从服务器推送通知

来自分类Dev

Android通过Firebase推送通知(服务器端)

来自分类Dev

Android通过Firebase推送通知(服务器端)

来自分类Dev

GCM-如何为Android推送通知生成服务器API密钥

来自分类Dev

使用laravel Web服务器上的Parse向Android设备发送推送通知

来自分类Dev

如何从Cordova中的服务器获取推送通知?

来自分类Dev

使用App引擎在Python服务器上推送通知

来自分类Dev

使用PHP从服务器发送推送通知

来自分类Dev

无法使用服务器API发送推送通知

来自分类Dev

使用FCM从服务器发送推送通知

来自分类Dev

使用Titan与PHP服务器生成iphone推送通知

来自分类Dev

如何通过使用Swift自己的PHP APNS服务器从推送通知中增加徽章号?

来自分类Dev

如何使用Firebase从服务器向应用程序发送推送通知?

来自分类Dev

解析推送通知是从服务器发送的,但客户端未接收到

来自分类Dev

从应用服务器接收GCM推送通知消息的步骤

来自分类Dev

在不使用服务器的情况下发送推送通知:将网络应用发送至Android

来自分类Dev

如何在 Nginx 服务器上使用 Drupal 8?

来自分类Dev

如何使用 SCCM 服务器推送带参数的 MSI

来自分类Dev

如何使用消息从服务器对象接收

来自分类Dev

如何在服务器中使用 imap 接收 gmail?

来自分类Dev

如何使用从服务器接收的 JSON 数据更新 UI?

来自分类Dev

APNS的反馈服务(Apple推送通知服务器)

来自分类Dev

GCM服务器将通知推送到C#中的android

来自分类Dev

PhoneGap-Android:我的服务器通过Urban Airship推送通知

来自分类Dev

从php服务器向Android设备发送批量推送通知

来自分类Dev

Xamarin.Android和Azure推送通知内部服务器错误

来自分类Dev

如何为交换服务器实现推送邮件通知?

来自分类Dev

如何在GCM推送通知的服务器端实现上验证注册?

Related 相关文章

  1. 1

    如果从我们的服务器推送,Android Parse Notification无法接收通知

  2. 2

    从服务器推送通知

  3. 3

    Android通过Firebase推送通知(服务器端)

  4. 4

    Android通过Firebase推送通知(服务器端)

  5. 5

    GCM-如何为Android推送通知生成服务器API密钥

  6. 6

    使用laravel Web服务器上的Parse向Android设备发送推送通知

  7. 7

    如何从Cordova中的服务器获取推送通知?

  8. 8

    使用App引擎在Python服务器上推送通知

  9. 9

    使用PHP从服务器发送推送通知

  10. 10

    无法使用服务器API发送推送通知

  11. 11

    使用FCM从服务器发送推送通知

  12. 12

    使用Titan与PHP服务器生成iphone推送通知

  13. 13

    如何通过使用Swift自己的PHP APNS服务器从推送通知中增加徽章号?

  14. 14

    如何使用Firebase从服务器向应用程序发送推送通知?

  15. 15

    解析推送通知是从服务器发送的,但客户端未接收到

  16. 16

    从应用服务器接收GCM推送通知消息的步骤

  17. 17

    在不使用服务器的情况下发送推送通知:将网络应用发送至Android

  18. 18

    如何在 Nginx 服务器上使用 Drupal 8?

  19. 19

    如何使用 SCCM 服务器推送带参数的 MSI

  20. 20

    如何使用消息从服务器对象接收

  21. 21

    如何在服务器中使用 imap 接收 gmail?

  22. 22

    如何使用从服务器接收的 JSON 数据更新 UI?

  23. 23

    APNS的反馈服务(Apple推送通知服务器)

  24. 24

    GCM服务器将通知推送到C#中的android

  25. 25

    PhoneGap-Android:我的服务器通过Urban Airship推送通知

  26. 26

    从php服务器向Android设备发送批量推送通知

  27. 27

    Xamarin.Android和Azure推送通知内部服务器错误

  28. 28

    如何为交换服务器实现推送邮件通知?

  29. 29

    如何在GCM推送通知的服务器端实现上验证注册?

热门标签

归档