【发布时间】: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");
}
}
}
【问题讨论】: