sane fallback for media selection on exception

Fixes #1763
// FREEBIE
This commit is contained in:
Jake McGinty 2014-10-16 01:48:59 -07:00
parent b5941fb3fd
commit 6e3751a0c5
2 changed files with 23 additions and 6 deletions

View File

@ -37,6 +37,9 @@
<string name="ApplicationPreferencesActivity_sms_disabled">Incoming SMS Disabled</string>
<string name="ApplicationPreferencesActivity_touch_to_make_textsecure_your_default_sms_app">Touch to make TextSecure your default SMS app</string>
<!-- AttchmentManager -->
<string name="AttachmentManager_cant_open_media_selection">Can\'t find an app to select media.</string>
<!-- AttachmentTypeSelectorAdapter -->
<string name="AttachmentTypeSelectorAdapter_picture">Picture</string>

View File

@ -17,13 +17,16 @@
package org.thoughtcrime.securesms.mms;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.util.BitmapDecodingException;
@ -31,6 +34,7 @@ import org.thoughtcrime.securesms.util.BitmapDecodingException;
import java.io.IOException;
public class AttachmentManager {
private final static String TAG = AttachmentManager.class.getSimpleName();
private final Context context;
private final View attachmentView;
@ -101,16 +105,26 @@ public class AttachmentManager {
}
private static void selectMediaType(Activity activity, String type, int requestCode) {
final Intent intent;
final Intent intent = new Intent();
intent.setType(type);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
} else {
intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
try {
activity.startActivityForResult(intent, requestCode);
return;
} catch (ActivityNotFoundException anfe) {
Log.w(TAG, "couldn't complete ACTION_OPEN_DOCUMENT, no activity found. falling back.");
}
}
intent.setType(type);
intent.setAction(Intent.ACTION_GET_CONTENT);
try {
activity.startActivityForResult(intent, requestCode);
} catch (ActivityNotFoundException anfe) {
Log.w(TAG, "couldn't complete ACTION_GET_CONTENT intent, no activity found. falling back.");
Toast.makeText(activity, R.string.AttachmentManager_cant_open_media_selection, Toast.LENGTH_LONG).show();
}
}
private class RemoveButtonListener implements View.OnClickListener {