我想用解析收到推送通知,并在活动中显示。我怎样才能从parse通知的价值观?通知、并在、想用、价值观

2023-09-07 00:21:29 作者:云朵上的棉花糖

我试过这个保存推

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.

添加ParsePushReciever在你的主包中。

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" />

手机接送不了推送通知了,在QQ上这里显示关闭,在系统设置里又显示开启的,求大神指导

检查通知在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.
    }
}