Android推送通知消息被切断

时间:2014-03-24 13:50:29

标签: android push-notification

您正在开发一个项目,该项目使用推送通知来推送文本格式的信息。只有当我收到推送通知时,文本才会被切断并替换为“...”

当应用程序从接收方收到信息时,我正在使用NotificationCompaq构建器来构建我的通知。

这是我的GCMBroadcastReceiver我很确定问题出在Builder中,但我不确定我需要做些什么来修复它。

import utilities.CommonUtilities;
import android.app.Activity;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.widget.Toast;

import com.google.android.gms.gcm.GoogleCloudMessaging;

/**
 * Handles the incoming messages from the server.
 *
 */
public class GCMBroadcastReceiver extends BroadcastReceiver {


    static final String TAG = "GCMDemo";
    public static final int NOTIFICATION_ID = 1;
    private NotificationManager mNotificationManager;
    NotificationCompat.Builder builder;
    Context ctx;

    @Override
    public void onReceive(Context context, Intent intent) {
        GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
        ctx = context;
        String messageType = gcm.getMessageType(intent);

        String message = intent.getExtras().getString("price");

        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            sendNotification("Send error: " + intent.getExtras().toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            sendNotification("Deleted messages on server: " +
                    intent.getExtras().toString());
        } else {
            sendNotification(message);
        }
        setResultCode(Activity.RESULT_OK);
    }

    // Put the GCM message into a notification and post it.
    private void sendNotification(String msg) {
        mNotificationManager = (NotificationManager)
                ctx.getSystemService(Context.NOTIFICATION_SERVICE);

        PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0,
                new Intent(ctx, MainActivity.class), 0);

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(ctx)
                        .setSmallIcon(R.drawable.icon)
                        .setContentTitle(CommonUtilities.pushTitle)
                        .setStyle(new NotificationCompat.BigTextStyle())
                        .setContentText(msg)
                        .setLights(0xff00ff00, 300, 1000)
                        .setVibrate(CommonUtilities.pattern);


        Log.d(TAG, "Notification built " + mBuilder.toString());


        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());


        Toast.makeText(ctx, "New Message: " + msg, Toast.LENGTH_LONG).show();


    }
}

非常感谢任何帮助。

修改 在我的应用程序构建通知之前,我已经检查了从GCM收到的消息,并且我收到完整的消息,在接收消息期间没有任何内容被切断,因此它肯定与通知构建器有关。我似乎无法弄清楚是什么导致它这样做。

0 个答案:

没有答案