在自定义BroadcastReceiver中未在Android上接收解析推送通知

 恋之-风景- 发布于 2023-01-20 15:48

我可以使用Parse成功发送带有以下数据的推送通知,但无法在我的自定义广播接收器中接收消息.遵循Parse Android通知指南:https://parse.com/docs/push_guide#receiving/Android.任何帮助,将不胜感激!

发送推送:

ParseQuery userQuery = ParseInstallation.getQuery();
                userQuery.whereContainedIn("user", arg0);

                JSONObject data= null;
                try {
                    data = new JSONObject("{\"title\" : \"Hush!\"," +
                                            "\"intent\" : \"ChatWindowActivity\"," +
                                            "\"action\" : \"com.hush.UPDATE_STATUS\"," +
                                            "\"chatId\" :" + getObjectId() + "}");
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                ParsePush push = new ParsePush();
                push.setQuery(userQuery);
                push.setData(data);
                push.setMessage("One of your friends wants to chat...");
                push.sendInBackground();

AndroidManifest设置:


    
        
        
    


    
        
    


    
        
        

        
    

自定义推送接收器:

package com.hush;
import java.util.Iterator;

import org.json.JSONException; 
import org.json.JSONObject;

import android.content.BroadcastReceiver; import android.content.Context; 
import     android.content.Intent; import android.util.Log; import android.widget.Toast;

import com.parse.ParseAnalytics;

public class HushPushReceiver extends BroadcastReceiver {

private static final String TAG = "DEBUG"; 

  @Override
  public void onReceive(Context context, Intent intent) {
  Toast.makeText(context, "Push received!!!!.",Toast.LENGTH_LONG).show();
  ParseAnalytics.trackAppOpened(intent);
try {
  String action = intent.getAction();
  String channel = intent.getExtras().getString("com.parse.Channel");
  JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));

  Log.d(TAG, "got action " + action + " on channel " + channel + " with:");
  Iterator itr = json.keys();
  while (itr.hasNext()) {
    String key = (String) itr.next();
    Log.d(TAG, "..." + key + " => " + json.getString(key));
  }
} catch (JSONException e) {
  Log.d(TAG, "JSONException: " + e.getMessage());
}

}}

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有