推送通知不起作用 [英] Push notifications don't work

查看:68
本文介绍了推送通知不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是android的新手.我已经尝试了文档中提供的示例.但是,我没有收到任何推送通知,只是获得了通知图标,但没有内容和标题.谁能帮助我得到清除???????

I am newbie to android. I had tried the sample given in documentation., but iam not getting any push notification only iam getting the notification icon but no content and title. Can anyone help me in getting cleared??????

  1. 推送通知是否可以在模拟器中工作?
  2. 在此示例中,我找到了一个名为"Resultactivity"的类.使用此目的
    上课?
  1. Will push notification works in emulator or not?
  2. In this sample i found a class as "Resultactivity". Purpose of using this
    class?

我已经给出了下面的代码.

I had given the code below.

package com.example.pushnotification;

import android.os.Bundle;
import android.app.Activity;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.view.Menu;

public class Pushactivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pushactivity);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.notification_icon)
            .setContentTitle("Check Notification")
            .setContentText("This is to test push!");

    Intent resultIntent = new Intent(this, ResultActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(ResultActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    int mId = 10;
    mNotificationManager.notify(mId, mBuilder.build());
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.pushactivity, menu);
    return true;
}

}

预先感谢

推荐答案

当然可以.我用的是gcm,它可以在模拟器和真实设备中使用.

Surely it will work. I used gcm,it worked in emulator and real device.

您必须从android sdk管理器安装google cloud消息传递并使用gcm.jar.

You must install google cloud messaging from android sdk manager and use gcm.jar.

这是可以测试它的最佳教程.

This is the best tutorial where you can test it.http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

这篇关于推送通知不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆