0

I am trying to implement App invites in my app. Here's the java code that I am using :

 Intent intent = new AppInviteInvitation.IntentBuilder(getString(R.string.invitation_title))
                    .build();
            startActivityForResult(intent, Constants.REQUEST_CODE_INVITE);

But, as soon as I am clicking on the button which executes this code, a dialog pops up saying 'Unfortunately, Google Play Services has stopped'. I have tried disabling, uninstalling and installing google play services again, and even restarting the phone, but no use.

No Exception is shown in android studio logs, so I am not able to figure out the problem is.

Please help.

Yash
  • 5,225
  • 4
  • 32
  • 65

2 Answers2

0

There are a few issues here, and I'd also you to validate values.

  1. getString requires resources. Assuming you are calling this from in an activity, you need to call getResources().getString(R.....). You are likely getting null returned which would result in an exception.
  2. Although there is only 1 required parameter, you should fill out a few more to make sure you have a reasonable invitation, specifically setMessage(). Also, you can use setAccount() if you know the account, otherwise it will prompt.

I would also validate the input values. For example, log the string value you get for R.string.invitation_title to make sure you have set this correctly before you call the builder.

Jim Cunningham
  • 282
  • 1
  • 5
  • Hey, thanks for the help. But I was doing some other mistake as I have mentioned below in my answer. – Yash Mar 31 '16 at 03:18
0

I was making a silly mistake which was leading to the error.

I was not initializing the GoogleApiClient before sending out the intent. Don't know how I missed it. Here's the code that I was missing :

GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(AppInvite.API)
            .enableAutoManage(this, this)
            .build();

Hope it helps future visitors to this page.

Yash
  • 5,225
  • 4
  • 32
  • 65