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:example.com.sunshine.app.ForecastFragment.java

private void openPreferredLocationInMap() {
    if (mForecastAdapter != null) {
        // Using the URI scheme for showing a location found on a map.  This super-handy
        // intent can is detailed in the "Common Intents" page of Android's developer site:
        // http://developer.android.com/guide/components/intents-common.html#Maps
        Cursor c = mForecastAdapter.getCursor();
        c.moveToPosition(0);//w  w  w  .j  av a  2s.c o m
        String longCord = c.getString(COL_COORD_LONG);
        String latCord = c.getString(COL_COORD_LAT);
        Uri geoLocation = Uri.parse("geo:" + latCord + ", " + longCord).buildUpon().build();

        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(geoLocation);
        if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
            startActivity(intent);
        } else {
            Log.d(LOG_TAG, "Couldn't call " + geoLocation + ", no receiving apps installed!");
        }
        c.close();
    }
}

From source file:com.univpm.s1055802.faceplusplustester.Detect.AcquireVideo.java

/**
 * Richiama la fotocamera, acquisisce il video e lo salva in un file
 * @return il file salvato/*from ww  w.j  av  a 2s. com*/
 */
private void Acquire() {
    Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    videoFile = null;
    if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go

        try {
            videoFile = createVideoFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
            Log.v("alert", "file error");
        }
        // Continue only if the File was successfully created
        if (videoFile != null) {
            takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(videoFile));
            takeVideoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);

            startActivityForResult(takeVideoIntent, REQUEST_TAKE_VIDEO);
        }
    }
}

From source file:com.udacity.sunshine.fragment.ForecastFragment.java

private void openPreferredLocationInMap() {
    // Using the URI scheme for showing a location found on a map. This super-handy
    // intent can is detailed in the "Common Intents" page of Android's developer site:
    // http://developer.android.com/guide/components/intents-common.html#Maps
    if (null != mForecastAdapter) {
        Cursor cursor = mForecastAdapter.getCursor();
        if (null != cursor) {

            if (!cursor.moveToFirst())
                return;

            cursor.moveToPosition(0);//from w  w w . ja  v  a  2 s. c o  m
            String posLat = cursor.getString(COL_COORD_LAT);
            String posLong = cursor.getString(COL_COORD_LONG);
            Uri geoLocation = Uri.parse("geo:" + posLat + "," + posLong);

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

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

From source file:de.westnordost.streetcomplete.about.AboutFragment.java

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    addPreferencesFromResource(R.xml.about);

    findPreference("version").setSummary(BuildConfig.VERSION_NAME);

    findPreference("license").setOnPreferenceClickListener(preference -> {
        Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://www.gnu.org/licenses/gpl-3.0.html"));
        startActivity(browserIntent);//from  w  w w  .j  a  va2s  . co m
        return true;
    });

    findPreference("authors").setOnPreferenceClickListener(preference -> {
        getFragmentActivity().setCurrentFragment(new CreditsFragment());
        return true;
    });

    findPreference("privacy").setOnPreferenceClickListener(preference -> {
        Fragment f = ShowHtmlFragment.create(
                getResources().getString(R.string.privacy_html) + getString(R.string.privacy_html_tileserver)
                        + getString(R.string.privacy_html_third_party_quest_sources)
                        + getString(R.string.privacy_html_image_upload2),
                R.string.about_title_privacy_statement);
        getFragmentActivity().setCurrentFragment(f);
        return true;
    });

    findPreference("repository").setOnPreferenceClickListener(preference -> {
        Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://github.com/westnordost/StreetComplete/"));
        startActivity(browserIntent);
        return true;
    });

    findPreference("report_error").setOnPreferenceClickListener(preference -> {
        Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://github.com/westnordost/StreetComplete/issues/"));
        startActivity(browserIntent);
        return true;
    });

    findPreference("email_feedback").setOnPreferenceClickListener(preference -> {
        Intent intent = new Intent(Intent.ACTION_SENDTO);
        intent.setData(Uri.parse("mailto:"));
        intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "osm@westnordost.de" });
        intent.putExtra(Intent.EXTRA_SUBJECT, ApplicationConstants.USER_AGENT + " Feedback");
        if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
            startActivity(intent);
            return true;
        }
        return false;
    });
}

From source file:io.github.hidroh.materialistic.FavoriteFragment.java

@Synthetic
void export(ArrayList<Favorite> favorites) {
    if (mProgressDialog != null) {
        mProgressDialog.dismiss();//from  w ww  .  ja va2  s . c o m
    }
    final Intent intent = AppUtils.makeEmailIntent(getString(R.string.favorite_email_subject),
            makeEmailContent(favorites));
    if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
        startActivity(intent);
    }
}

From source file:com.example.zayankovsky.homework.ui.ImageDetailActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.save:
        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                    MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
        } else {//www. j  av a 2s  .  c  om
            saveImageToGallery();
        }
        return true;
    case R.id.browser:
        Uri webpage = Uri.parse(FotkiWorker.getUrl());
        Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
            return true;
        }
        return false;
    case R.id.open:
        Uri imageUri = getUriForImage();
        if (imageUri == null) {
            return false;
        }

        Intent openIntent = new Intent();
        openIntent.setAction(Intent.ACTION_VIEW);
        // Put the Uri and MIME type in the result Intent
        openIntent.setDataAndType(imageUri, getContentResolver().getType(imageUri));
        // Grant temporary read permission to the content URI
        openIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivity(openIntent);
        return true;
    case R.id.share:
        imageUri = getUriForImage();
        if (imageUri == null) {
            return false;
        }

        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        // Put the Uri and MIME type in the result Intent
        shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
        shareIntent.setType(getContentResolver().getType(imageUri));
        // Grant temporary read permission to the content URI
        shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivity(Intent.createChooser(shareIntent, null));
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:com.desitum.landscape_connect.activities.HomeActivity.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;
    }//w w  w.  j  a v a2  s .  co m
    // Handle action buttons
    switch (item.getItemId()) {
    case R.id.action_settings:
        // 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, "not available", Toast.LENGTH_LONG).show();
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.nexus.nsnik.randomno.view.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int menuItemId = item.getItemId();
    switch (menuItemId) {
    case R.id.menuSettings:
        startActivityForResult(new Intent(MainActivity.this, PreferenceActivity.class),
                PREFERENCE_REQUEST_CODE);
        break;/*from   w  ww .ja v  a 2 s . co m*/
    case R.id.menuAbout:
        new AboutDialogFragment().show(getSupportFragmentManager(), "AboutDialog");
        break;
    case R.id.menuFeedback:
        Intent sentEmail = new Intent(Intent.ACTION_SENDTO);
        sentEmail.setData(Uri.parse("mailto:"));
        sentEmail.putExtra(Intent.EXTRA_EMAIL, getResources().getString(R.string.developerEmailAddress));
        sentEmail.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.emailSubject));
        if (sentEmail.resolveActivity(getPackageManager()) != null)
            startActivity(sentEmail);
        break;
    }
    return true;
}

From source file:com.example.android.diegobaldi.sunshine.MainActivity.java

/**
 * 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   ww w  .j  a  v  a  2  s  .  c  o  m
 *
 * @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 openPreferredLocationInMap() {
    double[] coords = SunshinePreferences.getLocationCoordinates(this);
    String posLat = Double.toString(coords[0]);
    String posLong = Double.toString(coords[1]);
    Uri geoLocation = Uri.parse("geo:" + posLat + "," + posLong);

    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.luke.lukef.lukeapp.NewUserActivity.java

/**
 * Creates the intent to start camera//w w w  .ja  v a2s .  c o m
 */
private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go

        if (photoFile != null) {
            this.photoPath = photoFile.getAbsolutePath();
            // Continue only if the File was successfully created
            Uri photoURI = FileProvider.getUriForFile(this, "com.luke.lukef.lukeapp", photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        } else {
            createImageFile();
            dispatchTakePictureIntent();
        }
    }
}