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:com.metinkale.prayerapp.utils.PermissionUtils.java

public void needNotificationPolicy(final Activity act) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return;//w w  w  .  j a v a  2 s.  c o m
    }
    NotificationManager nm = (NotificationManager) act.getSystemService(Context.NOTIFICATION_SERVICE);
    pNotPolicy = nm.isNotificationPolicyAccessGranted();
    if (!pNotPolicy) {
        Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);

        PackageManager packageManager = act.getPackageManager();
        if (intent.resolveActivity(packageManager) != null) {
            act.startActivity(intent);
        } else {
            ActivityCompat.requestPermissions(act,
                    new String[] { Manifest.permission.ACCESS_NOTIFICATION_POLICY }, 0);
        }
    }
}

From source file:com.jackie.sunshine.app.ForecastFragment.java

private void openPreferredLocationMap() {

    if (mForecastAdapter != null) {
        Cursor c = mForecastAdapter.getCursor();
        String postLat = c.getString(COL_COORD_LAT);
        String postLong = c.getString(COL_COORD_LONG);
        Uri geoLocation = Uri.parse("geo:" + postLat + "," + postLong);

        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(geoLocation);/*  w  w w.j ava  2 s . c o m*/

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

From source file:com.doctoror.fuckoffmusicplayer.presentation.base.BaseActivity.java

@Override
public boolean navigateUpTo(final Intent upIntent) {
    ComponentName destInfo = upIntent.getComponent();
    if (destInfo == null) {
        destInfo = upIntent.resolveActivity(getPackageManager());
        if (destInfo == null) {
            return false;
        }/*from  ww  w.j  a v  a2  s  .com*/
    }

    if (shouldUpRecreateTask(upIntent)) {
        startActivity(upIntent);
        finish();
    } else {
        ActivityCompat.finishAfterTransition(this);
    }
    return true;
}

From source file:com.tlongdev.bktf.ui.activity.AboutActivity.java

/**
 * Shows the simplified settings UI if the device configuration if the
 * device configuration dictates that a simplified, single-pane UI should be
 * shown.//from   ww w.  ja v  a  2s . c o m
 */
private void setupSimplePreferencesScreen() {

    // Add 'general' preferences.
    addPreferencesFromResource(R.xml.pref_about);

    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);

    // Bind the summaries of EditText/List/Dialog/Ringtone preferences to
    // their values. When their values change, their summaries are updated
    // to reflect the new value, per the Android Design guidelines.

    findPreference(getString(R.string.pref_title_feedback))
            .setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    //Start an email intent with my email as the target
                    Intent intent = new Intent(Intent.ACTION_SENDTO,
                            Uri.fromParts("mailto", "dev@tlongdev.com", null));
                    if (intent.resolveActivity(getPackageManager()) != null) {
                        startActivity(Intent.createChooser(intent, getString(R.string.message_send_email)));
                    }
                    return true;
                }
            });

    findPreference(getString(R.string.pref_title_rate))
            .setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    //Open the Play Store page of the app
                    final String appPackageName = getPackageName();
                    try {
                        startActivity(new Intent(Intent.ACTION_VIEW,
                                Uri.parse("market://details?id=" + appPackageName)));
                    } catch (android.content.ActivityNotFoundException e) {
                        //Play store is not present on the phone. Open the browser
                        CustomTabActivityHelper.openCustomTab(AboutActivity.this,
                                new CustomTabsIntent.Builder().build(),
                                Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName),
                                new WebViewFallback());
                    }
                    return true;
                }
            });

    //Set the version name to the summary, so I don't have to change it manually every goddamn
    //update
    findPreference(getString(R.string.pref_title_version)).setSummary(BuildConfig.VERSION_NAME);
}

From source file:com.example.nitish.welcomapp.activitypt.AboutFragment.java

/**
 * Open an email client to send a support request.
 *///from  ww w.  j a v a2s .c o  m
private void openEmail() {
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { getString(R.string.aboutEmail) });
    intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.aboutEmailSubject, BuildConfig.VERSION_NAME));
    if (intent.resolveActivity(getContext().getPackageManager()) != null) {
        startActivity(Intent.createChooser(intent, getString(R.string.aboutSendEmail)));
    } else {
        Toast.makeText(getContext(), R.string.errorNoEmail, Toast.LENGTH_LONG).show();
    }
}

From source file:uk.org.freeflight.wifefinder.MainActivity.java

void showMap() {
    // Display labelled marker at aircraft position
    String uri_str = String.format("geo:%f,%f?z=8&q=%f,%f(%s)", aircraftPosition.latitude,
            aircraftPosition.longitude, aircraftPosition.latitude, aircraftPosition.longitude,
            Uri.encode(db.getAircraftReg((id))));
    Uri gmmIntentUri = Uri.parse(uri_str);

    Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
    if (mapIntent.resolveActivity(getPackageManager()) != null) {
        startActivity(mapIntent);//from   w  ww .  jav a  2  s .  c o m
    }
}

From source file:com.nicefontaine.seanachie.ui.imagestory.ImageStoryFragment.java

private void photo() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
        try {/*  w  w  w.  j  a  v  a 2 s  . com*/
            File photoFile = FileUtils.createImageFile();
            cacheImagePath(photoFile.getAbsolutePath());
            Uri photoURI = FileProvider.getUriForFile(getActivity(), REPOSITORY, photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            getActivity().startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        } catch (IOException e) {
            Timber.e(e);
        }
    }
}

From source file:com.bar.foldinglayout.sample.FoldingPaneLayoutActivity.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  ww w . j  a  va2s .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.example.android.emojify.MainActivity.java

/**
 * Creates a temporary image file and captures a picture to store in it.
 *///w  ww. j ava2  s  .  c o  m
private void launchCamera() {

    // Create the capture image intent
    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 temporary File where the photo should go
        File photoFile = null;
        try {
            photoFile = BitmapUtils.createTempImageFile(this);
        } catch (IOException ex) {
            // Error occurred while creating the File
            ex.printStackTrace();
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {

            // Get the path of the temporary file
            mTempPhotoPath = photoFile.getAbsolutePath();

            // Get the content URI for the image file
            Uri photoURI = FileProvider.getUriForFile(this, FILE_PROVIDER_AUTHORITY, photoFile);

            // Add the URI so the camera can store the image
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);

            // Launch the camera activity
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        }
    }
}

From source file:org.wheelmap.android.fragment.profile.LoginFragment.java

private void register() {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    String url = BuildConfig.API_BASE_URL + Constants.Api.WM_REGISTER_LINK;
    if (!url.startsWith("http")) {
        url = "http://" + url;
    }//from w w w  .ja va2  s. c  o m
    intent.setData(Uri.parse(url));
    if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
        startActivity(intent);
    }
}