Android的 - 推送通知空白当不上了吧顶部 [英] Android - Push notification blank when not on top of the bar

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

问题描述

我有一个小问题与Android推送通知

如果有3声明和只有这些显示的标题和消息中的一个。的其中之一是在杆的顶部。如果任何人有任何想法可能是什么问题,请让我知道

请参考图片的链接,这是怎么了能够接收通知
http://postimg.org/image/3z4a21ssp/

 公共无效createNotification(上下文的背景下,捆绑演员)
{
    NotificationManager mNotificationManager =(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    字符串的appName = getAppName(本);    意图notificationIntent =新意图(这一点,PushHandlerActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra(pushBundle,临时演员);    的PendingIntent contentIntent = PendingIntent.getActivity(这一点,0,notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);    NotificationCompat.Builder mBuilder =
        新NotificationCompat.Builder(上下文)
            .setDefaults(Notification.DEFAULT_ALL)
            .setSmallIcon(context.getApplicationInfo()图标)
            .setWhen(System.currentTimeMillis的())
            //.setContentTitle(extras.getString(\"title))
            //.setTicker(extras.getString(\"title))
            .setContentIntent(co​​ntentIntent);    字符串消息= extras.getString(信息);
    //添加尝试捕捉的情况下,旧的code不工作!
    尝试{
        // chgpk:增加了这个$​​ C $ C得到较大的通知窗口
        NotificationCompat.BigTextStyle inboxStyle =新NotificationCompat.BigTextStyle();
        inboxStyle.setBigContentTitle(extras.getString(标题));
        inboxStyle.bigText(消息);
        mBuilder.setStyle(inboxStyle);    }赶上(例外前){
        如果(消息!= NULL){
            mBuilder.setContentText(消息);
        }其他{
            mBuilder.setContentText(<丢失邮件内容和GT;);
        }        NotificationCompat.InboxStyle inboxStyleEx =
                新NotificationCompat.InboxStyle();
        inboxStyleEx.setBigContentTitle(extras.getString(标题));
        inboxStyleEx.addLine(消息);
        mBuilder.setStyle(inboxStyleEx);
    }
    串msgcnt = extras.getString(msgcnt);
    如果(msgcnt!= NULL){
        mBuilder.setNumber(的Integer.parseInt(msgcnt));
    }    MY_NOTIFICATION_ID ++;
    //mNotificationManager.notify((String)的appName,NOTIFICATION_ID,mBuilder.build());
    mNotificationManager.notify((字符串)的appName,MY_NOTIFICATION_ID,mBuilder.build());
}

另外code从DOT NET IS

 的WebRequest tRequest;
        // tRequest = WebRequest.Create(https://android.googleapis.com/gcm/send);
        tRequest = WebRequest.Create(vANDR_PN_url);        tRequest.Method =邮报;
        tRequest.ContentType =应用/的X WWW的形式urlen codeD;字符集= UTF-8;
        tRequest.Headers.Add(的String.Format(授权:键= {0},GoogleAppID));        tRequest.Headers.Add(的String.Format(发件人:ID = {0},SENDER_ID));        串POSTDATA =
            collapse_key的= score_update&安培;
            +time_to_live = 108
            +与& delay_while_idle = 1
            +&放大器; data.message =+值
            +与& data.time =+ System.DateTime.Now.ToString()
            +与& data.title =+ contentTitle
            +与& data.redirect_to_page =+ vredirect_to_page
            +与& registration_id =+ DEVICEID +;        Console.WriteLine(POSTDATA);
        字节[]的字节数组= Encoding.UTF8.GetBytes(POSTDATA);
        tRequest.ContentLength = byteArray.Length;        流数据流= tRequest.GetRequestStream();
        dataStream.Write(字节数组,0,byteArray.Length);
        dataStream.Close();        WebResponse类tResponse = tRequest.GetResponse();        数据流= tResponse.GetResponseStream();        StreamReader的踏浪=新的StreamReader(数据流);        串sResponseFromServer = tReader.ReadToEnd();        System.IO.File.AppendAllText(LOGFILEPATH,Environment.NewLine +sResponseFromServer>>中+ sResponseFromServer);
        如果(sResponseFromServer ==错误= InvalidRegistration){
            MSTATUS =错误;
        }        tReader.Close();
        dataStream.Close();
        tResponse.Close();


解决方案

我觉得现在的问题是,你设置的bigStyle文本而不是默认的(小)查看。

将所有文本:

  //小 - 默认样式
NotificationCompat.Builder mBuilder =
    新NotificationCompat.Builder(上下文)
        .setDefaults(Notification.DEFAULT_ALL)
        .setSmallIcon(context.getApplicationInfo()图标)
        .setWhen(System.currentTimeMillis的())
        .setContentTitle(extras.getString(标题))
        .setTicker(extras.getString(标题))
        .setContentIntent(co​​ntentIntent);
//大牌风范
NotificationCompat.BigTextStyle inboxStyle =新NotificationCompat.BigTextStyle();
    inboxStyle.setBigContentTitle(extras.getString(标题));
    inboxStyle.bigText(消息);
    mBuilder.setStyle(inboxStyle);

I'm having a small issue with android push notifications

If there are 3 Notifications and only one of these displays the title and the message. The one which is on the top of the bar. If anyone has any idea what might be the issue please let me know

Refer image on this link, this is how i am able to receive notifications http://postimg.org/image/3z4a21ssp/

public void createNotification(Context context, Bundle extras)
{
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    String appName = getAppName(this);

    Intent notificationIntent = new Intent(this, PushHandlerActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("pushBundle", extras);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(context)
            .setDefaults(Notification.DEFAULT_ALL)
            .setSmallIcon(context.getApplicationInfo().icon)
            .setWhen(System.currentTimeMillis())
            //.setContentTitle(extras.getString("title"))
            //.setTicker(extras.getString("title"))
            .setContentIntent(contentIntent);

    String message = extras.getString("message");


    //Added Try catch in case the old code doesnt work !
    try{
        //chgpk: Added this code to get bigger notification window
        NotificationCompat.BigTextStyle inboxStyle = new NotificationCompat.BigTextStyle();
        inboxStyle.setBigContentTitle(extras.getString("title"));
        inboxStyle.bigText(message);        
        mBuilder.setStyle(inboxStyle);

    }catch(Exception ex){
        if (message != null) {
            mBuilder.setContentText(message);
        } else {
            mBuilder.setContentText("<missing message content>");
        }

        NotificationCompat.InboxStyle inboxStyleEx =
                new NotificationCompat.InboxStyle();
        inboxStyleEx.setBigContentTitle(extras.getString("title"));
        inboxStyleEx.addLine(message);
        mBuilder.setStyle(inboxStyleEx);
    }


    String msgcnt = extras.getString("msgcnt");     
    if (msgcnt != null) {
        mBuilder.setNumber(Integer.parseInt(msgcnt));
    }

    MY_NOTIFICATION_ID++;
    //mNotificationManager.notify((String) appName, NOTIFICATION_ID, mBuilder.build());
    mNotificationManager.notify((String) appName, MY_NOTIFICATION_ID, mBuilder.build());


}

Also Code from DOT NET IS

 WebRequest tRequest;
        //tRequest = WebRequest.Create("https://android.googleapis.com/gcm/send");
        tRequest = WebRequest.Create(vANDR_PN_url);

        tRequest.Method = "post";
        tRequest.ContentType = " application/x-www-form-urlencoded;charset=UTF-8";
        tRequest.Headers.Add(string.Format("Authorization: key={0}", GoogleAppID));

        tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));

        string postData =
            "collapse_key=score_update&"
            + "time_to_live=108"
            + "&delay_while_idle=1"
            + "&data.message=" + value
            + "&data.time=" + System.DateTime.Now.ToString()
            + "&data.title=" + contentTitle
            + "&data.redirect_to_page=" + vredirect_to_page
            + "&registration_id=" + deviceId + "";

        Console.WriteLine(postData);
        Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
        tRequest.ContentLength = byteArray.Length;

        Stream dataStream = tRequest.GetRequestStream();
        dataStream.Write(byteArray, 0, byteArray.Length);
        dataStream.Close();

        WebResponse tResponse = tRequest.GetResponse();

        dataStream = tResponse.GetResponseStream();

        StreamReader tReader = new StreamReader(dataStream);

        String sResponseFromServer = tReader.ReadToEnd();

        System.IO.File.AppendAllText(LogFilePath, Environment.NewLine + "sResponseFromServer >> " + sResponseFromServer);
        if (sResponseFromServer == "Error=InvalidRegistration") {
            mStatus = "error";
        }

        tReader.Close();
        dataStream.Close();
        tResponse.Close();

解决方案

I think that the problem is that you are setting texts for the bigStyle but not for the default (small) view.

Set all the texts:

// Small - default style
NotificationCompat.Builder mBuilder =
    new NotificationCompat.Builder(context)
        .setDefaults(Notification.DEFAULT_ALL)
        .setSmallIcon(context.getApplicationInfo().icon)
        .setWhen(System.currentTimeMillis())
        .setContentTitle(extras.getString("title"))
        .setTicker(extras.getString("title"))
        .setContentIntent(contentIntent);
// Big style
NotificationCompat.BigTextStyle inboxStyle = new NotificationCompat.BigTextStyle();
    inboxStyle.setBigContentTitle(extras.getString("title"));
    inboxStyle.bigText(message);        
    mBuilder.setStyle(inboxStyle);

这篇关于Android的 - 推送通知空白当不上了吧顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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