Example usage for android.content Intent resolveActivity

List of usage examples for android.content Intent resolveActivity

Introduction

In this page you can find the example usage for android.content Intent resolveActivity.

Prototype

public ComponentName resolveActivity(@NonNull PackageManager pm) 

Source Link

Document

Return the Activity component that should be used to handle this intent.

Usage

From source file:de.qspool.clementineremote.ui.fragments.DownloadsFragment.java

private void playFile(Uri file) {
    Intent mediaIntent = new Intent();
    mediaIntent.setAction(Intent.ACTION_VIEW);
    mediaIntent.setDataAndType(file, "audio/*");
    mediaIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    if (mediaIntent.resolveActivity(getActivity().getPackageManager()) != null) {
        startActivity(mediaIntent);//from   ww w  .j a  v  a 2  s  .  co  m
    } else {
        Toast.makeText(getActivity(), R.string.app_not_available, Toast.LENGTH_LONG).show();
    }
}

From source file:com.example.tobias.androidtestapp.navigationdrawer.NavigationDrawerMain.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // The action bar home/up action should open or close the drawer.
    // ActionBarDrawerToggle will take care of this.
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }//from   ww  w. jav a  2s .com
    // Handle action buttons
    switch (item.getItemId()) {
    case R.id.action_websearch:
        // Im Web nach dem Planeten suchen der aktuell angezeigt wird
        Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
        intent.putExtra(SearchManager.QUERY, getSupportActionBar().getTitle());
        // falls Webbrowser installiert, diesen mit unserem Suchbegriff starten
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        } else {
            // falls kein Webbrowser installiert, Toast machen
            Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show();
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:ua.com.elius.sunshine.app.ForecastFragment.java

private void openPreferredLocationInMap() {

    if (mForecastAdapter != null) {
        Cursor c = mForecastAdapter.getCursor();
        if (c != null) {
            c.moveToPosition(0);/*from  w w w  . j a v a 2s  .  c  o  m*/
            String latitude;
            String longitude;
            latitude = c.getString(COL_COORD_LAT);
            longitude = c.getString(COL_COORD_LONG);

            Uri geoLocation = Uri.parse("geo:" + latitude + "," + longitude);
            Log.d(LOG_TAG, geoLocation.toString());

            Intent viewLocationIntent;
            viewLocationIntent = new Intent();
            viewLocationIntent.setAction(Intent.ACTION_VIEW);
            viewLocationIntent.setData(geoLocation);

            if (viewLocationIntent.resolveActivity(getActivity().getPackageManager()) != null) {
                startActivity(viewLocationIntent);
            }
        }
    }
}

From source file:com.ultramegasoft.flavordex2.fragment.AbsPhotosFragment.java

/**
 * Launch an image capturing Intent./*from   w w  w.j a v  a 2 s. c o m*/
 */
final void takePhoto() {
    final Context context = getContext();
    final Fragment parent = getParentFragment();
    if (context == null || parent == null) {
        return;
    }

    final Intent intent = PhotoUtils.getTakePhotoIntent(context);
    if (intent != null && intent.resolveActivity(getContext().getPackageManager()) != null) {
        mCapturedPhoto = intent.getParcelableExtra(MediaStore.EXTRA_OUTPUT);
        parent.startActivityForResult(intent, REQUEST_CAPTURE_IMAGE);
        return;
    }
    Toast.makeText(context, R.string.error_camera, Toast.LENGTH_LONG).show();
}

From source file:com.sharklee.navigationDrawer.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // mDrawerToggleup???true???
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }/*www . j  av a2 s  .c  om*/
    // Handle action buttons
    switch (item.getItemId()) {
    case R.id.action_websearch:
        // create intent to perform web search for this planet
        Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
        intent.putExtra(SearchManager.QUERY, getActionBar().getTitle());
        //??Intent??
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        } else {
            Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show();
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.wit.android.support.content.intent.MapIntent.java

/**
 *///from www.j  av  a  2 s  .c  om
@Override
protected boolean onStart(@NonNull Intent intent) {
    final Context context = mContextWrapper.getContext();
    if (context == null) {
        return false;
    }
    if (intent.resolveActivity(context.getPackageManager()) != null) {
        return super.onStart(intent);
    }
    Log.e(TAG, "Maps not found.");
    return false;
}

From source file:com.example.android.navigationdrawerexample.activities.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // The action bar home/up action should open or close the drawer.
    // ActionBarDrawerToggle will take care of this.
    if (drawerToggle.onOptionsItemSelected(item)) {
        return true;
    }//from   w  w  w. j  a va 2 s  .c  o m
    // Handle action buttons
    switch (item.getItemId()) {
    case R.id.action_websearch:
        // create intent to perform web search for this planet
        Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
        intent.putExtra(SearchManager.QUERY, getActionBar().getTitle());
        // catch event that there's no activity to handle intent
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        } else {
            Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show();
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.fa.mastodon.activity.LoginActivity.java

private void redirectUserToAuthorizeAndLogin(EditText editText) {
    /* To authorize this app and log in it's necessary to redirect to the domain given,
     * activity_login there, and the server will redirect back to the app with its response. */
    String endpoint = MastodonAPI.ENDPOINT_AUTHORIZE;
    String redirectUri = getOauthRedirectUri();
    Map<String, String> parameters = new HashMap<>();
    parameters.put("client_id", clientId);
    parameters.put("redirect_uri", redirectUri);
    parameters.put("response_type", "code");
    parameters.put("scope", OAUTH_SCOPES);
    String url = "https://" + domain + endpoint + "?" + toQueryString(parameters);
    Uri uri = Uri.parse(url);/*w w  w.j a  va  2  s . c o  m*/
    if (!openInCustomTab(uri, this)) {
        Intent viewIntent = new Intent(Intent.ACTION_VIEW, uri);
        if (viewIntent.resolveActivity(getPackageManager()) != null) {
            startActivity(viewIntent);
        } else {
            editText.setError(getString(R.string.error_no_web_browser_found));
        }
    }
}

From source file:com.delaroystudios.weatherapp.MainActivity.java

/**
 * This method uses the URI scheme for showing a location found on a map in conjunction with
 * an implicit Intent. This super-handy intent is detailed in the "Common Intents" page of
 * Android's developer site:/*from w w w  .ja v  a  2  s  .c om*/
 *
 * @see "http://developer.android.com/guide/components/intents-common.html#Maps"
 * <p>
 * Protip: Hold Command on Mac or Control on Windows and click that link to automagically
 * open the Common Intents page
 */
private void openLocationInMap() {
    String addressString = WeatherPreferences.getPreferredWeatherLocation(this);
    Uri geoLocation = Uri.parse("geo:0,0?q=" + addressString);

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(geoLocation);

    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    } else {
        Log.d(TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!");
    }
}

From source file:com.example.d062654.faciliman._2_IncidentPicture.java

private void captureImage() {

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (intent.resolveActivity(ll.getContext().getPackageManager()) != null) {
        // Create the File where the photo should go

        try {/*from w w  w .  j a  v a  2s.co  m*/
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File

        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            Uri photoURI = FileProvider.getUriForFile(ll.getContext(), "com.d062654.fileprovider", photoFile);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(intent, REQUEST_TAKE_PHOTO);
        }
    }

}