0

我正在尝试在我的应用中实现应用邀请。这是我正在使用的java代码:

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

但是,当我单击执行此代码的按钮时,会弹出一个对话框,说'Unfortunately, Google Play Services has stopped'. 我已尝试再次禁用、卸载和安装 google play 服务,甚至重新启动手机,但没有用。

android studio日志中没有显示异常,所以我无法找出问题所在。

请帮忙。

4

2 回答 2

0

这里有一些问题,我也希望您验证值。

  1. getString 需要资源。假设您在活动中调用它,则需要调用 getResources().getString(R.....)。您可能会返回 null ,这将导致异常。
  2. 虽然只有 1 个必需参数,但您应该多填写几个以确保您有合理的邀请,特别是 setMessage()。另外,知道账号的可以使用setAccount(),否则会提示。

我还将验证输入值。例如,记录您为 R.string.invitation_title 获得的字符串值,以确保您在调用构建器之前已正确设置此值。

于 2016-03-30T15:43:31.077 回答
0

我犯了一个导致错误的愚蠢错误。

在发出意图之前,我没有初始化 GoogleApiClient。不知道我怎么错过了。这是我缺少的代码:

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

希望它可以帮助将来访问此页面的访问者。

于 2016-03-31T03:17:53.777 回答