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.skubware.opentraining.activity.create_exercise.ImageFragment.java

private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
        try {//from w w  w. ja  va2s.c o m
            mTempImageUri = createImageFile(false);
        } catch (IOException ex) {
            // Error occurred while creating the File
            Log.e(TAG, "Error creating image file", ex);
        }
        takePictureIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mTempImageUri);
        startActivityForResult(takePictureIntent, CreateExerciseActivity.TAKE_PICTURE);
    } else {
        Log.e(TAG, "No camera activity for handling camera intent");
    }
}

From source file:com.cse.rajat.sunshine.app.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 c = mForecastAdapter.getCursor();
        if (null != c) {
            c.moveToPosition(0);/*from   w ww .j  a v  a  2s. c o  m*/
            String posLat = c.getString(COL_COORD_LAT);
            String posLong = c.getString(COL_COORD_LONG);
            Uri geoLocation = Uri.parse("geo:" + posLat + "," + posLong);

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

            Log.d(LOG_TAG, "Location" + geoLocation.toString());

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

    }
}

From source file:com.example.android.navigationdrawerexample.ContentDrawerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // 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, getSupportActionBar().getTitle());
        // catch event that there's no activity to handle intent
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);/*from w w w.  jav  a2  s .  c  o m*/
        } else {
            Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show();
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.songnick.blogdemo.NetEaseDemo_Activity.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;
    }/*www . j  ava  2  s  . c om*/
    // 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, R.string.app_not_available, Toast.LENGTH_LONG).show();
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.jazz.MyActivity.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  w  ww.  j a  va2s .c  o  m
    // Handle action buttons
    switch (item.getItemId()) {
    case R.id.action_search:
        // 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:br.com.dsasoft.example.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 (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }//ww w  .  j a v  a2 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, getSupportActionBar().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:cn.androidy.swiftlib.navigationdrawer.NavigationDrawerActivity.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  w  w  w  .  j  a  v a2s . com*/
    // 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.glandorf1.joe.wsprnetviewer.app.DetailFragment.java

private void openGridsquareInMap(String gridsquare, String label) {
    if (gridsquare.length() > 0) {
        Double lat = Utility.gridsquareToLatitude(gridsquare);
        Double lon = Utility.gridsquareToLongitude(gridsquare);
        // Use the URI 'geo' scheme to show a gridsquare location on a map.
        // See http://developer.android.com/guide/components/intents-common.html#Maps
        //   "geo:<lat>,<long>?q=<lat>,<long>(LabelName)"
        Uri geoGridsquare = Uri.parse("geo:" + lat.toString() + "," + lon.toString() + "?").buildUpon()
                .appendQueryParameter("q", lat.toString() + "," + lon.toString() + "(" + label + ")")
                // TODO: zoom level doesn't seem to do anything
                //       ex: geo:?q=37.9375%2C-122.29166666666666(Tx%3A%20CM87uw)&z=4
                .appendQueryParameter("z", "4").build();
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(geoGridsquare);/*from w  w w  . j av  a  2  s .com*/
        if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
            Log.d(LOG_TAG, "Call '" + geoGridsquare.toString() + "'.");
            startActivity(intent);
        } else {
            Log.d(LOG_TAG, "Couldn't call '" + geoGridsquare.toString() + "', no receiving apps installed!");
        }
    }
}

From source file:com.katamaditya.apps.weather4u.WeatherForecastFragment.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 != mWeatherForecastAdapter) {
        Cursor c = mWeatherForecastAdapter.getCursor();
        if (null != c) {
            c.moveToPosition(0);//  w  w  w  .j  a  v  a 2s. c o m
            String posLat = c.getString(COL_COORD_LAT);
            String posLong = c.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(LOG_TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!");
              }*/
        }

    }
}

From source file:edu.cmu.ece.ece551.uis.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // 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);//from  w  ww  .  j  a v  a  2s . c  o  m
        } else {
            Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show();
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}