Ryan Tensmeyer
Ryan Tensmeyer

Reputation: 875

ParseInstallation.getCurrentInstallation().saveInBackground(); not working

I have created an app in iOS that uses Parse to store data and also uses Parse Push for messaging between users. I am now converting the app to Android and trying to use the same Parse backend for both. I am successfully uploading/downloading data and I can even send a message from an Android user to a iOS user, but I can't get my Android device to receive messages. The underlining problem seems to be 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 for a new installation in the database, but nothing ever shows up. It seems as though ParseInstallation.getCurrentInstallation().saveInBackground(); is not doing anything. Am I missing something?

Upvotes: 3

Views: 3611

Answers (3)

Oubaida
Oubaida

Reputation: 1756

add "bolts-android-x.x.x" lib in libs folder. You can find it in the Parse SDK zip file

Upvotes: 1

kmityak
kmityak

Reputation: 461

Alternatively, you can use package-private method ParseInstallation.clearCurrentInstallationFromDisk(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);
        }
    }

Upvotes: 1

Lena Bru
Lena Bru

Reputation: 13947

the object associated with the installation on the given device does not have a row in the parse installation table, this is why you are getting the error, there are 2 possible solutions to this problem :

  • uninstalling the app, and reinstalling it (which is an unacceptable solution), or
  • manually clearing the app parse cache. see the answer for how to do that

This method must be called before you call 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;
    }

Upvotes: 6

Related Questions