我想用解析收到推送通知,并在活动中显示。我怎样才能从parse通知的价值观? [英] I want to receive push notification using parse and display it in an activity. How can I get the values from parse notification?

查看:178
本文介绍了我想用解析收到推送通知,并在活动中显示。我怎样才能从parse通知的价值观?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过这个保存推

ParseQuery parseq=ParseInstallation.getQuery();
parseq.whereEqualTo("role", "manager");

ParseObject p=ParseInstallation.getCurrentInstallation();

ParsePush push = new ParsePush();
push.setQuery(parseq);
push.setMessage("My measage");
push.sendInBackground();

现在我要得到我的消息接收通知后,并得到一个活动印制的响应。

Now I want to get my message after receiving notification and get the response printed in an activity.

推荐答案

您需要做以下从推送通知得到的值。

You need to do following for getting the value from push notification.


  1. 添加ParsePushReciever在你的主包中。

  1. Add the ParsePushReciever in your main package.

import android.app.NotificationManager;
import android.app.PendingIntent;

import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.support.v4.app.NotificationCompat;


import com.parse.ParsePushBroadcastReceiver;


public class ParsePushReciever extends ParsePushBroadcastReceiver {


@Override
public void onPushOpen(Context context, Intent intent) {
    AppLog.e("Push", "Clicked");
    Intent i = new Intent(context, MainActivity.class);
    i.putExtras(intent.getExtras());
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(i);
}

@Override
public void onReceive(Context context, Intent intent) {
    Log.d("Push Notification",intent.getExtras().get(ParsePushBroadcastReceiver.KEY_PUSH_DATA).toString());
    NotificationManager nm=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);

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

    builder.setSmallIcon(R.drawable.launcher);

    Intent newIntent=new Intent(context,MainActivity.class);
    newIntent.putExtra(context.getString(R.string.navigation_from_notification),true);
    newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
            Intent.FLAG_ACTIVITY_CLEAR_TASK);
    PendingIntent pi=PendingIntent.getActivity(context, 0, newIntent, 0);

    builder.setContentIntent(pi);

    builder.setContentText("Push Notification");

    Log.d("Notification", strMsg);

    nm.notify(1, builder.build());
}
}


  • 添加reciever在你的清单文件:

  • Add the reciever in your manifest file:

    <receiver android:name=".ParsePushReciever" android:exported="false" >
        <intent-filter>
            <action android:name="com.parse.push.intent.RECEIVE" />
            <action android:name="com.parse.push.intent.DELETE" />
            <action android:name="com.parse.push.intent.OPEN" />
        </intent-filter>
    </receiver>
    <meta-data
        android:name="com.parse.push.notification_icon"
        android:resource="@drawable/launcher" />
    


  • 检查通知在MainActivity:

  • Check for notification in your MainActivity:

    if(getIntent()!=null) {
    
        if (getIntent().getExtras()!=null &&
            getIntent().getExtras().getBoolean(getString(R.string.navigation_from_notification))) {
    
           //get data from intent and display it in your activity.
        }
    }
    


  • 这篇关于我想用解析收到推送通知,并在活动中显示。我怎样才能从parse通知的价值观?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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