Search in sources :

Example 86 with ActivityNotFoundException

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");
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent)

Example 87 with ActivityNotFoundException

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);
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent) Uri(android.net.Uri)

Example 88 with ActivityNotFoundException

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);
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) URLSpan(android.text.style.URLSpan) Uri(android.net.Uri)

Example 89 with ActivityNotFoundException

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();
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) DateException(com.android.calendarcommon2.DateException) Intent(android.content.Intent) Duration(com.android.calendarcommon2.Duration) Cursor(android.database.Cursor) Uri(android.net.Uri)

Example 90 with ActivityNotFoundException

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());
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent)

Aggregations

ActivityNotFoundException (android.content.ActivityNotFoundException)406 Intent (android.content.Intent)365 Uri (android.net.Uri)49 PendingIntent (android.app.PendingIntent)39 View (android.view.View)39 ResolveInfo (android.content.pm.ResolveInfo)38 RecognizerIntent (android.speech.RecognizerIntent)35 PackageManager (android.content.pm.PackageManager)30 UserHandle (android.os.UserHandle)28 ComponentName (android.content.ComponentName)26 ImageView (android.widget.ImageView)24 Bundle (android.os.Bundle)23 TextView (android.widget.TextView)23 Test (org.junit.Test)23 RemoteException (android.os.RemoteException)22 Activity (android.app.Activity)21 SearchManager (android.app.SearchManager)20 DialogInterface (android.content.DialogInterface)17 SearchableInfo (android.app.SearchableInfo)15 File (java.io.File)15