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.avpptr.umweltzone.map.ZoneNotDrawableDialog.java

@NonNull
@Override/* w w  w.  j av  a  2  s  .c  om*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final FragmentActivity activity = getActivity();
    final LowEmissionZone lowEmissionZone = LowEmissionZone.getRecentLowEmissionZone(activity);
    if (lowEmissionZone == null) {
        throw new NullPointerException("Recent low emission zone is null.");
    }
    final String zoneDisplayName = lowEmissionZone.displayName;

    // Prepare layout
    LayoutInflater inflater = activity.getLayoutInflater();
    View zoneNotDrawableView = inflater.inflate(R.layout.fragment_zone_not_drawable, null);
    TextView noticeTextView = (TextView) zoneNotDrawableView.findViewById(R.id.zone_not_drawable_notice);
    Spanned noticeSpanned = Html
            .fromHtml(getString(R.string.zone_not_drawable_notice, zoneDisplayName, zoneDisplayName));
    noticeTextView.setText(noticeSpanned, TextView.BufferType.SPANNABLE);

    // Launch dialog
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setView(zoneNotDrawableView).setTitle(R.string.zone_not_drawable_title)
            .setPositiveButton(R.string.zone_not_drawable_open_email, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, int whichButton) {
                    Intent intent = IntentHelper.getSendEmailIntent(activity,
                            getToRecipients(lowEmissionZone.contactEmails), getBccRecipients(),
                            getEmailSubject(zoneDisplayName), getEmailMessage(zoneDisplayName));
                    mTracking.track(TrackingPoint.ZoneNotDrawableOpenEmailClick, lowEmissionZone.name);
                    if (intent.resolveActivity(activity.getPackageManager()) != null) {
                        startActivity(Intent.createChooser(intent,
                                getString(R.string.zone_not_drawable_app_chooser_title)));
                    } else {
                        SnackBarHelper.showError(activity, R.id.map, R.string.zone_not_drawable_no_email_app);
                    }
                }
            }).setNegativeButton(R.string.zone_not_drawable_later, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, int whichButton) {
                    // Nothing to do here
                    mTracking.track(TrackingPoint.ZoneNotDrawableLaterClick, lowEmissionZone.name);
                }
            });
    return builder.create();
}

From source file:geert.stef.sm.beheerautokm.Overview.java

public void addNewImage(View view) {
    if (view.getId() == R.id.btnAddNewImage) {
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {

            File photoFile = null;
            try {
                photoFile = createImageFile(selectedCar.getCar());
            } catch (IOException ex) {
                // Error occurred while creating the File

            }/*from   w w  w  .  j a v  a 2 s . co  m*/
            // Continue only if the File was successfully created
            if (photoFile != null) {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                startActivityForResult(takePictureIntent, REQUEST_CODE_CAPTURE);
            }
        }
    }
}

From source file:io.realm.scanner.MainActivity.java

private void dispatchTakePicture() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        File photoFile = null;/*from   w  ww. j av  a 2 s  . com*/
        try {
            photoFile = createImageFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (photoFile != null) {
            currentPhotoPath = photoFile.getAbsolutePath();
            Uri photoURI = FileProvider.getUriForFile(this, "io.realm.scanner.fileprovider", photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        }
    }
}

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

private void setUpWebView(View view) {
    mProgressBar = (ProgressBar) view.findViewById(R.id.progress);
    mWebView.setBackgroundColor(Color.TRANSPARENT);
    mWebView.setWebViewClient(new AdBlockWebViewClient(Preferences.adBlockEnabled(getActivity())));
    mWebView.setWebChromeClient(new CacheableWebView.ArchiveClient() {
        @Override//from w  w w  .  j  a  va2  s. c  om
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            mProgressBar.setVisibility(VISIBLE);
            mProgressBar.setProgress(newProgress);
            if (!TextUtils.isEmpty(mUrl)) {
                mWebView.setBackgroundColor(Color.WHITE);
            }
            if (newProgress == 100) {
                mProgressBar.setVisibility(GONE);
                mWebView.setVisibility(mExternalRequired ? GONE : VISIBLE);
            }
            mButtonRefresh.setImageResource(
                    newProgress == 100 ? R.drawable.ic_refresh_white_24dp : R.drawable.ic_clear_white_24dp);
        }
    });
    mWebView.setDownloadListener((url, userAgent, contentDisposition, mimetype, contentLength) -> {
        if (getActivity() == null) {
            return;
        }
        final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        if (intent.resolveActivity(getActivity().getPackageManager()) == null) {
            return;
        }
        mExternalRequired = true;
        mWebView.setVisibility(GONE);
        view.findViewById(R.id.empty).setVisibility(VISIBLE);
        view.findViewById(R.id.download_button).setOnClickListener(v -> startActivity(intent));
    });
    AppUtils.toggleWebViewZoom(mWebView.getSettings(), false);
}

From source file:com.drmidnight.materialtest.MainActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    toolbar = (Toolbar) findViewById(R.id.tool_bar);
    setSupportActionBar(toolbar);/*from  www.  j a  v  a  2  s  .c o  m*/

    mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View

    mRecyclerView.setHasFixedSize(true); // Letting the system know that the list objects are of fixed size

    mAdapter = new MyAdapter(TITLES, ICONS, TITLES2, ICONS2, TITLES3, ICONS3, SUBTITLES, NAME, EMAIL, PROFILE,
            this); // Creating the Adapter of MyAdapter class(which we are going to see in a bit)
    // And passing the titles,icons,header view name, header view email,
    // and header view profile picture

    mRecyclerView.setAdapter(mAdapter); // Setting the adapter to RecyclerView

    final GestureDetector mGestureDetector = new GestureDetector(MainActivity.this,
            new GestureDetector.SimpleOnGestureListener() {

                @Override
                public boolean onSingleTapUp(MotionEvent e) {
                    return true;
                }

            });

    mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
        @Override
        public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
            View child = recyclerView.findChildViewUnder(motionEvent.getX(), motionEvent.getY());

            if (child != null && mGestureDetector.onTouchEvent(motionEvent)) {
                //Drawer.closeDrawers();
                Toast.makeText(MainActivity.this,
                        "The Item Clicked is: " + recyclerView.getChildPosition(child), Toast.LENGTH_SHORT)
                        .show();

                switch (recyclerView.getChildPosition(child)) {
                case 0:
                    //This is the header
                    break;
                case 1:
                    Drawer.closeDrawers();
                    break;
                case 2:
                    Drawer.closeDrawers();
                    Intent diningintent = new Intent(MainActivity.this, DiningActivity.class);
                    startActivity(diningintent);
                    break;
                case 3:
                    Drawer.closeDrawers();
                    break;
                case 4:
                    Drawer.closeDrawers();
                    break;
                case 5:
                    Drawer.closeDrawers();
                    break;
                case 6:
                    //This is a line
                    break;
                case 7:
                    //This is a subtitle
                    break;
                case 8:
                    Drawer.closeDrawers();
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                            Uri.parse("https://my.ucsc.edu/psp/ep9prd/?cmd=login&languageCd=ENG"));
                    if (browserIntent.resolveActivity(getPackageManager()) != null) {
                        startActivity(browserIntent);
                    }
                    break;
                case 9:
                    Drawer.closeDrawers();
                    Intent browserIntent2 = new Intent(Intent.ACTION_VIEW,
                            Uri.parse("https://ecommons.ucsc.edu/portal/login"));
                    if (browserIntent2.resolveActivity(getPackageManager()) != null) {
                        startActivity(browserIntent2);
                    }
                    break;
                case 10:
                    Drawer.closeDrawers();
                    Intent browserIntent3 = new Intent(android.content.Intent.ACTION_VIEW,
                            Uri.parse("https://piazza.com/class"));
                    if (browserIntent3.resolveActivity(getPackageManager()) != null) {
                        startActivity(browserIntent3);
                    }
                    break;
                case 12:
                    Drawer.closeDrawers();
                    break;
                case 13:
                    Drawer.closeDrawers();
                    break;
                case 14:
                    Drawer.closeDrawers();
                    break;
                default:
                    break;
                }

                return true;

            }

            return false;
        }

        @Override
        public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {

        }
    });

    mLayoutManager = new LinearLayoutManager(this); // Creating a layout Manager

    mRecyclerView.setLayoutManager(mLayoutManager); // Setting the layout Manager

    Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout); // Drawer object Assigned to the view
    mDrawerToggle = new ActionBarDrawerToggle(this, Drawer, toolbar, R.string.navigation_drawer_open,
            R.string.navigation_drawer_close) {

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            // code here will execute once the drawer is opened( As I dont want anything happened whe drawer is
            // open I am not going to put anything here)
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            // Code here will execute once drawer is closed
        }

    }; // Drawer Toggle Object Made
    Drawer.setDrawerListener(mDrawerToggle); // Drawer Listener set to the Drawer toggle
    mDrawerToggle.syncState(); // Finally we set the drawer toggle sync State

}

From source file:com.alley.android.ppi.app.OverviewFragment.java

private void openPreferredLocationInMap() {
    if (null != mOverviewAdapter) {
        Cursor c = mOverviewAdapter.getCursor();
        if (null != c) {
            c.moveToPosition(0);/*from   w  w  w.  java  2 s  . c om*/
            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:ga.aditya.udacity01sunshine.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.getmCursor();
        if (null != c) {
            c.moveToPosition(0);/* w  ww .j a va  2  s  .c  om*/
            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:khoa.p.le.innerview.MainActivity.java

private void dispatchTakeVideoIntent() {
    Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
    }//w  ww. j  a va  2 s .  c om
}

From source file:com.example.android.phonecallingsamplechallenge.MainActivity.java

/**
 * Uses an implicit intent to make the phone call.
 * Before calling, checks to see if permission is granted.
 *
 * @param view View that was clicked.//from  w  ww . ja  va2 s.c  o  m
 */
public void callNumber(View view) {
    String normalizedPhoneNumber;
    // Find the editText_main view and assign it to editText.
    EditText editText = (EditText) findViewById(R.id.editText_main);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Log.d(TAG, "Running version earlier than Lollipop. Can't normalize number.");
        normalizedPhoneNumber = editText.getText().toString();
    } else {
        normalizedPhoneNumber = PhoneNumberUtils.normalizeNumber(editText.getText().toString());
    }
    // Use format with "tel:" and phone number to create phoneNumber.
    String phoneNumber = String.format("tel: %s", normalizedPhoneNumber);
    // Log the concatenated phone number for dialing.
    Log.d(TAG, getString(R.string.dial_number) + phoneNumber);
    Toast.makeText(this, getString(R.string.dial_number) + phoneNumber, Toast.LENGTH_LONG).show();
    // Create the intent.
    Intent callIntent = new Intent(Intent.ACTION_CALL);
    // Set the data for the intent as the phone number.
    callIntent.setData(Uri.parse(phoneNumber));
    // If package resolves to an app, check for phone permission,
    // and send intent.
    if (callIntent.resolveActivity(getPackageManager()) != null) {
        checkForPhonePermission();
        startActivity(callIntent);
    } else {
        Log.e(TAG, "Can't resolve app for ACTION_CALL Intent.");
    }
}

From source file:nazmul.storagesampletest.MainActivity.java

public void launchCamera(View view) {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;//  w  ww .j ava2s .  com
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            Toast.makeText(this, ex.getMessage(), Toast.LENGTH_SHORT).show();
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        }
    }
}