Skip to content

Commit

Permalink
Check if activity is available before using it in ArbitrayFileWidget (g…
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 authored and shobhitagarwal1612 committed Jan 11, 2019
1 parent bd64ced commit 523bf17
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@
import org.odk.collect.android.BuildConfig;
import org.odk.collect.android.R;
import org.odk.collect.android.activities.FormEntryActivity;
import org.odk.collect.android.utilities.ActivityAvailability;
import org.odk.collect.android.utilities.ApplicationConstants;
import org.odk.collect.android.utilities.FileUtil;
import org.odk.collect.android.utilities.FileUtils;
import org.odk.collect.android.utilities.MediaManager;
import org.odk.collect.android.utilities.MediaUtil;
import org.odk.collect.android.utilities.ToastUtils;
import org.odk.collect.android.widgets.interfaces.FileWidget;

import java.io.File;
Expand Down Expand Up @@ -194,6 +196,13 @@ private void openFile() {
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(contentUri, getMimeType(getSourcePathFromUri(fileUri)));
FileUtils.grantFileReadPermissions(intent, contentUri, getContext());
getContext().startActivity(intent);

if (new ActivityAvailability(getContext()).isActivityAvailable(intent)) {
getContext().startActivity(intent);
} else {
String message = getContext().getString(R.string.activity_not_found, getContext().getString(R.string.open_file));
ToastUtils.showLongToast(message);
Timber.w(message);
}
}
}
1 change: 1 addition & 0 deletions collect_app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -656,4 +656,5 @@
<string name="sms_invalid_phone_number_description">Set a destination phone number for SMS submissions or change your transport type.</string>
<string name="notification_channel_name">General notifications</string>
<string name="corrupt_imported_preferences_error">Current settings are corrupt. From the admin settings, reset settings or import working ones.</string>
<string name="open_file">Open file</string>
</resources>

0 comments on commit 523bf17

Please sign in to comment.