... ParseInstallation.getCurrentInstallation () saveInBackground (); does not work

I have created an app on iOS that uses Parse to store data and also uses Parse Push to exchange messages between users. Now I am converting my app to Android and am trying to use the same Parse component for both. I am uploading / downloading data successfully and I can even send a message from an Android user to an iOS user, but I cannot get my Android device to receive messages. The underscore issue is that I can't get the installation to work. I am calling this block of code from my onCreate function:

Parse.enableLocalDatastore(this);
Parse.initialize(this, "id1", "id2");
ParsePush.subscribeInBackground("", new SaveCallback() {
   @Override
   public void done(ParseException e) {
      if (e == null) {
         Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
      } else {
         Log.e("com.parse.push", "failed to subscribe for push", e);
      }
   }
});
ParseInstallation.getCurrentInstallation().saveInBackground();

      

After calling this code, I check the new installation in the database, but nothing appears. Seems to do ParseInstallation.getCurrentInstallation().saveInBackground();

nothing. Did I miss something?

+3


source to share


3 answers


the object associated with the installation on a given device does not have a row in the parsing installation table, so you get an error, there are 2 possible solutions to this problem:

  • uninstalling the application and reinstalling it (which is not an acceptable solution), or
  • manually clearing the application session analysis cache. see the answer on how to do that what


This method must be called before calling Parse.initialize ...

public static boolean deleteInstallationCache(Context context) {
        boolean deletedParseFolder = false;
        File cacheDir = context.getCacheDir();
        File parseApp = new File(cacheDir.getParent(),"app_Parse");
        File installationId = new File(parseApp,"installationId");
        File currentInstallation = new File(parseApp,"currentInstallation");
        if(installationId.exists()) {
            deletedParseFolder = deletedParseFolder || installationId.delete();
        }
        if(currentInstallation.exists()) {
         deletedParseFolder = deletedParseFolder && currentInstallation.delete();
        }
        return deletedParseFolder;
    }

      

+6


source


Alternatively you can use the private-private ParseInstallation.clearCurrentInstallationFromDisk method (context context)



    public static void clearParseInstallation(Context context) {
        try {
            Method method = ParseInstallation.class.getDeclaredMethod("clearCurrentInstallationFromDisk", Context.class);
            method.setAccessible(true);
            method.invoke(null, context);
        } catch (Exception e) {
            Log.e(e);
        }
    }

      

+1


source


add libts-android-xxx folder to libs folder. You can find it in the Parse SDK zip file

+1


source







All Articles