Android版的Dropbox核心API:没有返回身份验证后, [英] Dropbox Core API for Android: Not returning after Authentication

查看:95
本文介绍了Android版的Dropbox核心API:没有返回身份验证后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发两款Android应用程序:

I am developing two android applications:

  • 第一是用发射器等等
  • 一个正常的应用程序
  • 另一种是只有一个观众活性的应用程序(参见清单):

  • the first is a normal application with a launcher and so on
  • the other is a application only with a viewer activity (see the manifest):

<activity
    android:name=".MyActivity"
    android:icon="@drawable/icon"
    android:label="@string/dropbox" >
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
<activity
    android:name="com.dropbox.client2.android.AuthActivity"
    android:configChanges="orientation|keyboard"
    android:launchMode="singleTask" >
    <intent-filter>
        <data android:scheme="db-XXXXX" />

        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

该计划是,第一应用程序不需要互联网的权限,二是一些附加的第一位。

The plan is, that the first application does not need internet permissions and the second is some kind of add-on to the first.

第二个应用程序应同步与Dropbox的文件(与核心API,不与同步API)。

The second application should sync a file with Dropbox (with the Core API, not with the Sync API).

这是我的第一个应用程序,从我做起MyActivity这样从第二个应用程序:

From my first app, I start 'MyActivity' from the second app like this:

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setComponent(new ComponentName("my.package","my.package.MyActivity"));
    intent.putExtra("filePath", "/myFile.txt");
    startActivityForResult(intent, SYNC_REQUEST);

这是工作。活动出现和存在,如果没有被授权的是,用户必须preSS的一个按钮。那么下面code将被执行

That works. The Activity comes up and there, if not authorized yet, the user must press a button. Then the following code will be executed

    AndroidAuthSession session = buildSession();
    mApi = new DropboxAPI<AndroidAuthSession>(session);

    mApi.getSession().startAuthentication(MyActivity.this);

如果用户没有安装Dropbox的,浏览器将弹出。

If the user does not have dropbox installed, the browser will pop up.

一旦用户presses接受或拒绝,浏览器不会消失。它保持开放,MyActivity没有得到恢复并(onResume不叫!)。

As soon as the user presses 'Accept' or 'Decline', the browser does not disappear. It stays open and MyActivity does not get resumed (onResume is not called!).

我发现,在添加

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

开始MyActivity从我的第一个应用程序就能解决问题,但我可以不听前/等待MyActivity的结果。

before starting MyActivity from my first application will solve the problem, but then I can not listen/wait for the result of MyActivity.

我很沮丧。谁能帮助我或者给我一些建议?

I am frustrated. Can anyone help me or give me some advise?

谢谢!

推荐答案

当您使用startAuthentication方法。它会自动启动AuthActivity。你不需要()显式调用startActivity。然后在你活动的onResume方法写这篇code:

When you are using startAuthentication method. It will automatically start the AuthActivity. you do not need to call startActivity() explicitly. Then in onResume method of your activity write this code :

@Override
    protected void onResume()
    {
        super.onResume();
        if (if dropBoxAPI!= null && dropboxAPI.getSession().authenticationSuccessful())
        {
            try {

                dropboxAPI.getSession().finishAuthentication();
                oAuth2Token = dropboxAPI.getSession().getOAuth2AccessToken();
            }
            catch (IllegalStateException ie)
            {
                ie.printStackTrace();
            }
        }

    }

这篇关于Android版的Dropbox核心API:没有返回身份验证后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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