如何以编程方式从android中解析推送通知的订阅频道

时间:2015-09-26 09:01:47

标签: android parse-platform push-notification

我正在使用解析推送通知。所以,我做的是,我在使用应用程序ID和客户端密钥初始化解析时订阅了一个名为“EveryOne”的频道。

代码在应用程序类的onCreate()方法中是这样的:

    // Initialize Crash Reporting.
    ParseCrashReporting.enable(this);

    // Enable Local Datastore.
    Parse.enableLocalDatastore(this);

    // Add your initialization code here
    Parse.initialize(this, APPLICATION_ID, CLIENT_KEY);

    ParseUser.enableAutomaticUser();

    ParsePush.subscribeInBackground("EveryOne", new SaveCallback()
    {
          @Override
          public void done(ParseException e)
          {
                if (e == null)
                {
                  Log.d("From ParseApplication", "successfully subscribed to the broadcast channel.");
                }
                else
                {
                  Log.e("From ParseApplication", "failed to subscribe for push", e);
                }
          }
    });

    ParseInstallation.getCurrentInstallation().saveInBackground();

并从app发送推送通知:

JSONObject obj;

    try
    {
        obj = new JSONObject();
        obj.put("action","app.package.name.PushNotification");
        obj.put("customdata","Message comes here");
        obj.put("time", System.currentTimeMillis());

        ParsePush push = new ParsePush();
        ParseQuery<ParseInstallation> query = ParseInstallation.getQuery();

        query.whereEqualTo("channels", "EveryOne");
        push.setQuery(query);
        push.setData(obj);
        push.sendInBackground(new SendCallback()
        {   
            @Override
            public void done(ParseException arg0)
            {
                if(arg0 == null)
                {

// finish();                         Log.d(“if arg0”,“arg0:”+ arg0);

                    Toast.makeText(this, "Push Notificaiton Sent", Toast.LENGTH_SHORT).show();
                }
                else
                {
                    Log.d("else arg0", "arg0: "+arg0);

                    Toast.makeText(this, "Failed To Send Push Notificaiton", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
    catch (JSONException e)
    {
        e.printStackTrace();
    }

因此,谁安装了应用程序,每个人都会因为查询而获得推送通知:  query.whereEqualTo("channels", "EveryOne");

所以,现在我想以编程方式更新/删除已经订阅的频道从“EveryOne”到“IndividualOne”或“IndividualTwo”这样的不同名称,以便我可以将推送通知发送到选定的频道而不是通过更改查询来每个人: query.whereEqualTo("channels","IndividualTwo");

任何人都可以帮助我...

提前谢谢..

0 个答案:

没有答案