【问题标题】:Open custom file from Google Drive fails从 Google Drive 打开自定义文件失败
【发布时间】:2015-08-06 12:52:33
【问题描述】:

我的应用程序创建了具有自定义 Mime 类型的文件并将它们存储在 Google Drive 上。该应用程序也可以搜索并重新打开这些文件。但是,当我在 Google Drive 应用程序(不是我自己的应用程序)中单击文件时,打开的流程不起作用。

选择器意图按预期显示,仅列出了我的应用程序,但是当我选择我的应用程序时,Google Drive 应用程序会短暂显示一个永远不会启动的下载进度条,然后说存在内部错误。

我的设置如下,我希望有人能告诉我是什么原因造成的。尽管我认为此时实际上没有任何东西在联系我的应用程序。据我所知,开发者控制台已正确填写。

清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="...">
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/logo" android:label="@string/app_name"
    android:allowBackup="true" android:theme="@style/AppTheme">
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    <activity android:name=".MainActivity" android:label="@string/app_name"
        android:launchMode="singleTop" android:theme="@style/AppTheme">
        <meta-data android:name="com.google.android.apps.drive.APP_ID" android:value="id=..." />
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.google.android.apps.drive.DRIVE_OPEN" />
            <data android:mimeType="@string/app_mime" />
            <data android:mimeType="@string/file_mime" /> <!-- matches the file im clicking -->
        </intent-filter>
    </activity>
</application>

活动

public class MainActivity extends Activity {

private static final String ACTION_DRIVE_OPEN = "com.google.android.apps.drive.DRIVE_OPEN";
private static final String EXTRA_DRIVE_OPEN_ID = "resourceId";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ...
}

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);
}

@Override
protected void onResume() {
    super.onResume();
    handleIntent();
}

private void handleIntent() {
    Intent intent = getIntent();
    if (ACTION_DRIVE_OPEN.equals(intent.getAction())) {
        if (intent.getType().equals(getString(R.string.file_mime))) {
            String fileId = intent.getStringExtra(EXTRA_DRIVE_OPEN_ID);
            if (fileId != null && !"".equals(fileId)) {
                ...
            } else {
                Log.e(TAG, "Drive_Open has no valid file id - " + fileId);
            }
        } else {
            Log.e(TAG, "Drive_Open called on the wrong mime type - " + intent.getType() + " found, " + getString(R.string.file_mime) + " required");
        }
    }
}

【问题讨论】:

    标签: android google-drive-api


    【解决方案1】:

    经过一些测试,这似乎发生在驱动器应用程序连接到服务器以检索信息并将其传递给其他应用程序(或任何其他故障)之间存在超时。

    最初的问题会给你一个有意义的错误,但是驱动器应用程序似乎维护了一个缓存或其他东西,这会在以后的所有尝试中显示上述错误。

    解决方案是清除两个应用程序的数据(这可能有问题)或(我发现更容易)重新安装您正在开发/测试的应用程序。任何一种方法都可以阻止此问题再次发生。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多