Android Parse Push notification device registration only one time on one device

前端 未结 7 2037
礼貌的吻别
礼貌的吻别 2020-12-04 19:07

Every one I am using the parse service for push notification in my app. but it register all time when i re-install the app in one device.Then problem is that,one device rece

7条回答
  •  忘掉有多难
    2020-12-04 19:24

    I was also facing this issue. I sort of solved it by calling the below method in my Activity's onCreate()

    /**
         * Initialize Push Messaging Service and subscribe to all-users channel
         */
        private void initParsePushMessaging() {
            ParseInstallation parseInstallation = ParseInstallation
                    .getCurrentInstallation();
            //You might skip this if
            if (ParseUser.getCurrentUser() != null) {
                parseInstallation.put("user",
                        ParseUser.getCurrentUser());
            }
            if (parseInstallation.getObjectId() != null)
                parseInstallation.saveInBackground(new SaveCallback() {
    
                    @Override
                    public void done(ParseException e) {
                        PushService.subscribe(getApplicationContext(),"channel_name",
                                MainHomeActivity.class);
                    }
                });
    
        }
    

    Even though it didn't completely solve my problem but now my app doesn't hang and no more ANR's due to this Parse implementation. If i re install an app and run it now then the app creates a new installation record and remove's the last one. The only problem is that the channel_name is not subscribed on this run but on the next run the channel are successfully subscribed.

提交回复
热议问题