Search in sources :

Example 46 with ActivityNotFoundException

use of android.content.ActivityNotFoundException in project Libraries-for-Android-Developers by eoecn.

the class SearchView method onVoiceClicked.

private void onVoiceClicked() {
    // guard against possible race conditions
    if (mSearchable == null) {
        return;
    }
    SearchableInfo searchable = mSearchable;
    try {
        if (searchable.getVoiceSearchLaunchWebSearch()) {
            Intent webSearchIntent = createVoiceWebSearchIntent(mVoiceWebSearchIntent, searchable);
            getContext().startActivity(webSearchIntent);
        } else if (searchable.getVoiceSearchLaunchRecognizer()) {
            Intent appSearchIntent = createVoiceAppSearchIntent(mVoiceAppSearchIntent, searchable);
            getContext().startActivity(appSearchIntent);
        }
    } catch (ActivityNotFoundException e) {
        // Should not happen, since we check the availability of
        // voice search before showing the button. But just in case...
        Log.w(LOG_TAG, "Could not find voice search activity");
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) SearchableInfo(android.app.SearchableInfo) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent)

Example 47 with ActivityNotFoundException

use of android.content.ActivityNotFoundException in project materialistic by hidroh.

the class AppUtils method openPlayStore.

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void openPlayStore(Context context) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(PLAY_STORE_URL));
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    } else {
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    }
    try {
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(context, R.string.no_playstore, Toast.LENGTH_SHORT).show();
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) TargetApi(android.annotation.TargetApi)

Example 48 with ActivityNotFoundException

use of android.content.ActivityNotFoundException in project zxingfragmentlib by mitoyarzun.

the class CalendarResultHandler method addCalendarEvent.

/**
   * Sends an intent to create a new calendar event by prepopulating the Add Event UI. Older
   * versions of the system have a bug where the event title will not be filled out.
   *
   * @param summary A description of the event
   * @param start   The start time
   * @param allDay  if true, event is considered to be all day starting from start time
   * @param end     The end time (optional)
   * @param location a text description of the event location
   * @param description a text description of the event itself
   * @param attendees attendees to invite
   */
private void addCalendarEvent(String summary, Date start, boolean allDay, Date end, String location, String description, String[] attendees) {
    Intent intent = new Intent(Intent.ACTION_INSERT);
    intent.setType("vnd.android.cursor.item/event");
    long startMilliseconds = start.getTime();
    intent.putExtra("beginTime", startMilliseconds);
    if (allDay) {
        intent.putExtra("allDay", true);
    }
    long endMilliseconds;
    if (end == null) {
        if (allDay) {
            // + 1 day
            endMilliseconds = startMilliseconds + 24 * 60 * 60 * 1000;
        } else {
            endMilliseconds = startMilliseconds;
        }
    } else {
        endMilliseconds = end.getTime();
    }
    intent.putExtra("endTime", endMilliseconds);
    intent.putExtra("title", summary);
    intent.putExtra("eventLocation", location);
    intent.putExtra("description", description);
    if (attendees != null) {
        intent.putExtra(Intent.EXTRA_EMAIL, attendees);
    // Documentation says this is either a String[] or comma-separated String, which is right?
    }
    try {
        // Do this manually at first
        rawLaunchIntent(intent);
    } catch (ActivityNotFoundException anfe) {
        Log.w(TAG, "No calendar app available that responds to " + Intent.ACTION_INSERT);
        // For calendar apps that don't like "INSERT":
        intent.setAction(Intent.ACTION_EDIT);
        // Fail here for real if nothing can handle it
        launchIntent(intent);
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent)

Example 49 with ActivityNotFoundException

use of android.content.ActivityNotFoundException in project k-9 by k9mail.

the class FileBrowserHelper method showFileBrowserActivity.

/**
     * tries to open known filebrowsers.
     * If no filebrowser is found and fallback textdialog is shown
     * @param c the context as activity
     * @param startPath: the default value, where the filebrowser will start.
     *      if startPath = null => the default path is used
     * @param requestcode: the int you will get as requestcode in onActivityResult
     *      (only used if there is a filebrowser installed)
     * @param callback: the callback (only used when no filebrowser is installed.
     *      if a filebrowser is installed => override the onActivtyResult Method
     *
     * @return true: if a filebrowser has been found (the result will be in the onActivityResult
     *          false: a fallback textinput has been shown. The Result will be sent with the callback method
     *
     *
     */
public boolean showFileBrowserActivity(Activity c, File startPath, int requestcode, FileBrowserFailOverCallback callback) {
    boolean success = false;
    if (startPath == null) {
        startPath = new File(K9.getAttachmentDefaultPath());
    }
    int listIndex = 0;
    do {
        String intentAction = PICK_DIRECTORY_INTENTS[listIndex][0];
        String uriPrefix = PICK_DIRECTORY_INTENTS[listIndex][1];
        Intent intent = new Intent(intentAction);
        intent.setData(Uri.parse(uriPrefix + startPath.getPath()));
        try {
            c.startActivityForResult(intent, requestcode);
            success = true;
        } catch (ActivityNotFoundException e) {
            // Try the next intent in the list
            listIndex++;
        }
    } while (!success && (listIndex < PICK_DIRECTORY_INTENTS.length));
    if (listIndex == PICK_DIRECTORY_INTENTS.length) {
        //No Filebrowser is installed => show a fallback textdialog
        showPathTextInput(c, startPath, callback);
        success = false;
    }
    return success;
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent) File(java.io.File)

Example 50 with ActivityNotFoundException

use of android.content.ActivityNotFoundException in project k-9 by k9mail.

the class FileBrowserHelper method showFileBrowserActivity.

public boolean showFileBrowserActivity(Fragment c, File startPath, int requestcode, FileBrowserFailOverCallback callback) {
    boolean success = false;
    if (startPath == null) {
        startPath = new File(K9.getAttachmentDefaultPath());
    }
    int listIndex = 0;
    do {
        String intentAction = PICK_DIRECTORY_INTENTS[listIndex][0];
        String uriPrefix = PICK_DIRECTORY_INTENTS[listIndex][1];
        Intent intent = new Intent(intentAction);
        intent.setData(Uri.parse(uriPrefix + startPath.getPath()));
        try {
            c.startActivityForResult(intent, requestcode);
            success = true;
        } catch (ActivityNotFoundException e) {
            // Try the next intent in the list
            listIndex++;
        }
    } while (!success && (listIndex < PICK_DIRECTORY_INTENTS.length));
    if (listIndex == PICK_DIRECTORY_INTENTS.length) {
        //No Filebrowser is installed => show a fallback textdialog
        showPathTextInput(c.getActivity(), startPath, callback);
        success = false;
    }
    return success;
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent) File(java.io.File)

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