在Android NDK中为AccountPicker接收onActivityResult [英] Receiving onActivityResult in Android NDK for AccountPicker

查看:177
本文介绍了在Android NDK中为AccountPicker接收onActivityResult的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将NDK应用程式与Google云端硬碟整合。我遵循示例应用,并根据我的本机代码进行调整。我已经成功启动帐户选择器,但现在卡住了如何从帐户选择器获得结果。我使用代码中的JNI调用启动帐户选择器

I am trying to integrate my NDK application with Google Drive. I am following the Sample Application and adapting it to being used from my native code. I have gotten it to launch the account picker successfully, but am now stuck at how to get the result from the account picker. I launch the account picker using JNI calls from my code

在代码示例中,调用 onActivityResult 当其他意图返回时的活动。

In the code sample, the onActivityResult method is called on the activity when other intents return.

@Override
  protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    switch (requestCode) {
    case REQUEST_ACCOUNT_PICKER:
      if (resultCode == RESULT_OK && data != null && data.getExtras() != null) {
        String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
        if (accountName != null) {
          credential.setSelectedAccountName(accountName);
          service = getDriveService(credential);
          startCameraIntent();
        }
      }
      break;
    }
  }

有办法做一个类似的事情使用NDK?我想在C中创建一个函数并将其设置为 onActivityResult 的回调。

Is there a way to do a similar thing using the NDK? I want to create a function in C and set it as the callback for onActivityResult.

推荐答案

唯一的解决方案是不太理想。你必须创建一个NativeActivity的Java子类,并在那里实现onActivityResult结果。在你的AndroidManifest.xml中,你将引用你的新子类<​​code> activity android:name =而不是NativeActivity。

The only solution is a less than ideal one. You have to create a Java subclass of NativeActivity, and implement onActivityResult result there. In your AndroidManifest.xml you'll reference your new subclass activity android:name="" instead of NativeActivity.

这篇关于在Android NDK中为AccountPicker接收onActivityResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆