use of android.content.ActivityNotFoundException in project android by owncloud.
the class FileOperationsHelper method openFile.
public void openFile(OCFile file) {
if (file != null) {
String storagePath = file.getStoragePath();
Intent intentForSavedMimeType = new Intent(Intent.ACTION_VIEW);
intentForSavedMimeType.setDataAndType(file.getExposedFileUri(mFileActivity), file.getMimetype());
intentForSavedMimeType.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
Intent intentForGuessedMimeType = null;
if (storagePath.lastIndexOf('.') >= 0) {
String guessedMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));
if (guessedMimeType != null && !guessedMimeType.equals(file.getMimetype())) {
intentForGuessedMimeType = new Intent(Intent.ACTION_VIEW);
intentForGuessedMimeType.setDataAndType(file.getExposedFileUri(mFileActivity), guessedMimeType);
intentForGuessedMimeType.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
}
}
Intent openFileWithIntent;
if (intentForGuessedMimeType != null) {
openFileWithIntent = intentForGuessedMimeType;
} else {
openFileWithIntent = intentForSavedMimeType;
}
List<ResolveInfo> launchables = mFileActivity.getPackageManager().queryIntentActivities(openFileWithIntent, PackageManager.GET_INTENT_FILTERS);
if (launchables != null && launchables.size() > 0) {
try {
mFileActivity.startActivity(Intent.createChooser(openFileWithIntent, mFileActivity.getString(R.string.actionbar_open_with)));
} catch (ActivityNotFoundException anfe) {
mFileActivity.showSnackMessage(mFileActivity.getString(R.string.file_list_no_app_for_file_type));
}
} else {
mFileActivity.showSnackMessage(mFileActivity.getString(R.string.file_list_no_app_for_file_type));
}
} else {
Log_OC.e(TAG, "Trying to open a NULL OCFile");
}
}
use of android.content.ActivityNotFoundException in project android-app-common-tasks by multidots.
the class CropImageActivity method takePicture.
private void takePicture() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
try {
Uri mImageCaptureUri;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
mImageCaptureUri = Uri.fromFile(mFileTemp);
} else {
/*
* The solution is taken from here: http://stackoverflow.com/questions/10042695/how-to-get-camera-result-as-a-uri-in-data-folder
*/
mImageCaptureUri = InternalStorageContentProvider.CONTENT_URI;
}
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
intent.putExtra("return-data", true);
startActivityForResult(intent, REQUEST_CODE_TAKE_PICTURE);
} catch (ActivityNotFoundException e) {
Log.d(TAG, "cannot take picture", e);
}
}
use of android.content.ActivityNotFoundException in project Etar-Calendar by Etar-Group.
the class AlertReceiver method onReceive.
@Override
public void onReceive(final Context context, final Intent intent) {
if (AlertService.DEBUG) {
Log.d(TAG, "onReceive: a=" + intent.getAction() + " " + intent.toString());
}
if (DELETE_ALL_ACTION.equals(intent.getAction())) {
// The user has dismissed a digest notification.
// TODO Grab a wake lock here?
Intent serviceIntent = new Intent(context, DismissAlarmsService.class);
context.startService(serviceIntent);
} else if (MAP_ACTION.equals(intent.getAction())) {
// Try starting the map action.
// If no map location is found (something changed since the notification was originally
// fired), update the notifications to express this change.
final long eventId = intent.getLongExtra(EXTRA_EVENT_ID, -1);
if (eventId != -1) {
URLSpan[] urlSpans = getURLSpans(context, eventId);
Intent geoIntent = createMapActivityIntent(context, urlSpans);
if (geoIntent != null) {
// Location was successfully found, so dismiss the shade and start maps.
try {
context.startActivity(geoIntent);
} catch (ActivityNotFoundException exception) {
Toast.makeText(context, context.getString(R.string.no_map), Toast.LENGTH_SHORT).show();
}
closeNotificationShade(context);
} else {
// No location was found, so update all notifications.
// Our alert service does not currently allow us to specify only one
// specific notification to refresh.
AlertService.updateAlertNotification(context);
}
}
} else if (CALL_ACTION.equals(intent.getAction())) {
// Try starting the call action.
// If no call location is found (something changed since the notification was originally
// fired), update the notifications to express this change.
final long eventId = intent.getLongExtra(EXTRA_EVENT_ID, -1);
if (eventId != -1) {
URLSpan[] urlSpans = getURLSpans(context, eventId);
Intent callIntent = createCallActivityIntent(context, urlSpans);
if (callIntent != null) {
// Call location was successfully found, so dismiss the shade and start dialer.
context.startActivity(callIntent);
closeNotificationShade(context);
} else {
// No call location was found, so update all notifications.
// Our alert service does not currently allow us to specify only one
// specific notification to refresh.
AlertService.updateAlertNotification(context);
}
}
} else if (MAIL_ACTION.equals(intent.getAction())) {
closeNotificationShade(context);
// Now start the email intent.
final long eventId = intent.getLongExtra(EXTRA_EVENT_ID, -1);
if (eventId != -1) {
Intent i = new Intent(context, QuickResponseActivity.class);
i.putExtra(QuickResponseActivity.EXTRA_EVENT_ID, eventId);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
} else {
Intent i = new Intent();
i.setClass(context, AlertService.class);
i.putExtras(intent);
i.putExtra("action", intent.getAction());
Uri uri = intent.getData();
// This intent might be a BOOT_COMPLETED so it might not have a Uri.
if (uri != null) {
i.putExtra("uri", uri.toString());
}
beginStartingService(context, i);
}
}
use of android.content.ActivityNotFoundException in project Etar-Calendar by Etar-Group.
the class GoogleCalendarUriIntentFilter method onCreate.
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
Intent intent = getIntent();
if (intent != null) {
Uri uri = intent.getData();
if (uri != null) {
String[] eidParts = extractEidAndEmail(uri);
if (eidParts == null) {
Log.i(TAG, "Could not find event for uri: " + uri);
} else {
final String syncId = eidParts[0];
final String ownerAccount = eidParts[1];
if (debug)
Log.d(TAG, "eidParts=" + syncId + "/" + ownerAccount);
final String selection = Events._SYNC_ID + " LIKE \"%" + syncId + "\" AND " + Calendars.OWNER_ACCOUNT + " LIKE \"" + ownerAccount + "\"";
if (debug)
Log.d(TAG, "selection: " + selection);
Cursor eventCursor = getContentResolver().query(Events.CONTENT_URI, EVENT_PROJECTION, selection, null, Calendars.CALENDAR_ACCESS_LEVEL + " desc");
if (debug)
Log.d(TAG, "Found: " + eventCursor.getCount());
if (eventCursor == null || eventCursor.getCount() == 0) {
Log.i(TAG, "NOTE: found no matches on event with id='" + syncId + "'");
return;
}
Log.i(TAG, "NOTE: found " + eventCursor.getCount() + " matches on event with id='" + syncId + "'");
try {
// Get info from Cursor
while (eventCursor.moveToNext()) {
int eventId = eventCursor.getInt(EVENT_INDEX_ID);
long startMillis = eventCursor.getLong(EVENT_INDEX_START);
long endMillis = eventCursor.getLong(EVENT_INDEX_END);
if (debug)
Log.d(TAG, "_id: " + eventCursor.getLong(EVENT_INDEX_ID));
if (debug)
Log.d(TAG, "startMillis: " + startMillis);
if (debug)
Log.d(TAG, "endMillis: " + endMillis);
if (endMillis == 0) {
String duration = eventCursor.getString(EVENT_INDEX_DURATION);
if (debug)
Log.d(TAG, "duration: " + duration);
if (TextUtils.isEmpty(duration)) {
continue;
}
try {
Duration d = new Duration();
d.parse(duration);
endMillis = startMillis + d.getMillis();
if (debug)
Log.d(TAG, "startMillis! " + startMillis);
if (debug)
Log.d(TAG, "endMillis! " + endMillis);
if (endMillis < startMillis) {
continue;
}
} catch (DateException e) {
if (debug)
Log.d(TAG, "duration:" + e.toString());
continue;
}
}
// Pick up attendee status action from uri clicked
int attendeeStatus = Attendees.ATTENDEE_STATUS_NONE;
if ("RESPOND".equals(uri.getQueryParameter("action"))) {
try {
switch(Integer.parseInt(uri.getQueryParameter("rst"))) {
case // Yes
1:
attendeeStatus = Attendees.ATTENDEE_STATUS_ACCEPTED;
break;
case // No
2:
attendeeStatus = Attendees.ATTENDEE_STATUS_DECLINED;
break;
case // Maybe
3:
attendeeStatus = Attendees.ATTENDEE_STATUS_TENTATIVE;
break;
}
} catch (NumberFormatException e) {
// ignore this error as if the response code
// wasn't in the uri.
}
}
final Uri calendarUri = ContentUris.withAppendedId(Events.CONTENT_URI, eventId);
intent = new Intent(Intent.ACTION_VIEW, calendarUri);
intent.setClass(this, EventInfoActivity.class);
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, startMillis);
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endMillis);
if (attendeeStatus == Attendees.ATTENDEE_STATUS_NONE) {
startActivity(intent);
} else {
updateSelfAttendeeStatus(eventId, ownerAccount, attendeeStatus, intent);
}
finish();
return;
}
} finally {
eventCursor.close();
}
}
}
// Can't handle the intent. Pass it on to the next Activity.
try {
startNextMatchingActivity(intent);
} catch (ActivityNotFoundException ex) {
// no browser installed? Just drop it.
}
}
finish();
}
use of android.content.ActivityNotFoundException in project XobotOS by xamarin.
the class Credentials method unlock.
public void unlock(Context context) {
try {
Intent intent = new Intent(UNLOCK_ACTION);
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.w(LOGTAG, e.toString());
}
}
Aggregations