Skip to content

Commit

Permalink
sane fallback for media selection on exception
Browse files Browse the repository at this point in the history
Fixes #1763
// FREEBIE
  • Loading branch information
mcginty committed Oct 18, 2014
1 parent b5941fb commit 6e3751a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
3 changes: 3 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
26 changes: 20 additions & 6 deletions src/org/thoughtcrime/securesms/mms/AttachmentManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@
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;

import java.io.IOException;

public class AttachmentManager {
private final static String TAG = AttachmentManager.class.getSimpleName();

private final Context context;
private final View attachmentView;
Expand Down Expand Up @@ -101,16 +105,26 @@ public static void selectAudio(Activity activity, int requestCode) {
}

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);
activity.startActivityForResult(intent, requestCode);
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 {
Expand Down

1 comment on commit 6e3751a

@ayush19283
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi can you please tell how did you handle the case android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.OPEN_DOCUMENT_TREE flg=0x1 }

I am getting this error in my app and unable to resolve it. Please help

Please sign in to comment.