* Less picky about the mime type's we accept.

* Handling content and files the same way
* Improved support for sharing files in

fixes AntennaPod/AntennaPod#827
This commit is contained in:
Tom Hennen 2015-05-25 21:48:06 -04:00
parent bafdc86ca0
commit dfcfe15dd0
3 changed files with 24 additions and 27 deletions

View File

@ -155,21 +155,14 @@
<data <data
android:host="*" android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.opml" android:pathPattern=".*\\.opml"
android:scheme="file"/> android:scheme="file"
</intent-filter> android:mimeType="*/*"/>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data <data
android:host="*" android:host="*"
android:pathPattern=".*\\.opml" android:pathPattern=".*\\.opml"
android:scheme="file" android:scheme="content"
android:mimeType="text/*"/> android:mimeType="*/*"/>
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity

View File

@ -1,17 +1,26 @@
package de.danoeh.antennapod.activity; package de.danoeh.antennapod.activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.util.LangUtils; import de.danoeh.antennapod.core.util.LangUtils;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL; import java.net.URL;
/** Lets the user start the OPML-import process. */ /** Lets the user start the OPML-import process. */
public class OpmlImportFromIntentActivity extends OpmlImportBaseActivity { public class OpmlImportFromIntentActivity extends OpmlImportBaseActivity {
private static final String TAG = "OpmlImportFromIntentAct";
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
setTheme(UserPreferences.getTheme()); setTheme(UserPreferences.getTheme());
@ -20,10 +29,10 @@ public class OpmlImportFromIntentActivity extends OpmlImportBaseActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
try { try {
URL mOpmlURL = new URL(getIntent().getData().toString()); Uri uri = getIntent().getData();
BufferedReader in = new BufferedReader(new InputStreamReader(mOpmlURL.openStream(),
LangUtils.UTF_8)); Reader mReader = new InputStreamReader(getContentResolver().openInputStream(uri), LangUtils.UTF_8);
startImport(in); startImport(mReader);
} catch (Exception e) { } catch (Exception e) {
new AlertDialog.Builder(this).setMessage("Cannot open XML - Reason: " + e.getMessage()).show(); new AlertDialog.Builder(this).setMessage("Cannot open XML - Reason: " + e.getMessage()).show();
} }

View File

@ -31,7 +31,7 @@ import de.danoeh.antennapod.core.util.StorageUtils;
*/ */
public class OpmlImportFromPathActivity extends OpmlImportBaseActivity { public class OpmlImportFromPathActivity extends OpmlImportBaseActivity {
private static final String TAG = "OpmlImportFromPathActivity"; private static final String TAG = "OpmlImportFromPathAct";
private static final int CHOOSE_OPML_FILE = 1; private static final int CHOOSE_OPML_FILE = 1;
@ -174,17 +174,12 @@ public class OpmlImportFromPathActivity extends OpmlImportBaseActivity {
if (resultCode == RESULT_OK && requestCode == CHOOSE_OPML_FILE) { if (resultCode == RESULT_OK && requestCode == CHOOSE_OPML_FILE) {
Uri uri = data.getData(); Uri uri = data.getData();
if ("content".equals(uri.getScheme())) {
try { try {
Reader mReader = new InputStreamReader(getContentResolver().openInputStream(uri), LangUtils.UTF_8); Reader mReader = new InputStreamReader(getContentResolver().openInputStream(uri), LangUtils.UTF_8);
startImport(mReader); startImport(mReader);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.d(TAG, "File not found"); Log.d(TAG, "File not found");
} }
} else {
String filename = uri.getPath();
startImport(new File(filename));
}
} }
} }