How to receive parse push notifiactions on an android device using parse.com

前端 未结 4 2135
别那么骄傲
别那么骄傲 2021-01-06 03:38

How to intent from parse push notification. i f anybody implemented parse push please help.

Parse.initialize(Splash.this,\"id\",\"id\");
ParseInstallation.ge         


        
4条回答
  •  感动是毒
    2021-01-06 04:32

    You have to write a parse broadcast receiver in order to receive notification.. Write in your manifest

      
            
                
            
        
    

    then define a broadcast receiver

    public class ParseBroadcastReceiver extends BroadcastReceiver{
    
    public static final String ACTION                       =   "com.example.package.MESSAGE";
    public static final String PARSE_EXTRA_DATA_KEY         =   "com.parse.Data";
    public static final String PARSE_JSON_CHANNEL_KEY       =   "com.parse.Channel";
    
    @Override
    public void onReceive(Context context, Intent intent) {
    
         String action = intent.getAction();
            String channel = intent.getExtras().getString(PARSE_JSON_CHANNEL_KEY);
            JSONObject json = new JSONObject(intent.getExtras().getString(PARSE_EXTRA_DATA_KEY));
    
        }
    

    Now this json object will contain the data that you have send from parse.. For instance if you have to send notification using javascript api

       Parse.Push.send({where: query, // Set our Installation query
                    data: {                   
                        triggerKey:triggerValue, 
                        objectType:"android",
                        action:"com.example.package.MESSAGE"
                    }
                  },{
                  success: function() {
                    // Push was successful
    
                  },
                  error: function(error) {
                    // Handle error
    
                  }
                });
    

    Note that in your push notification you have to mention the "action" key and it should be same as the one you have mentioned in your broadcast receiver intent filter.

提交回复
热议问题