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.apptentive.android.sdk.util.Util.java

public static boolean canLaunchIntent(Context context, Intent intent) {
    if (context == null) {
        return false;
    }/*from ww  w  . j a  v  a  2s.co  m*/

    PackageManager pm = context.getPackageManager();
    ComponentName cn = intent.resolveActivity(pm);
    if (cn != null) {
        return true;
    }
    return false;
}

From source file:com.shareyourproxy.IntentLauncher.java

/**
 * Launch Email Intent./*from   w  w  w  .  j  a  v a  2  s .  com*/
 *
 * @param activity context
 * @param address  to send to
 */
public static void launchEmailIntent(Activity activity, String address) {
    Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("mailto:"));

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { address });
    if (intent.resolveActivity(activity.getPackageManager()) != null) {
        activity.startActivity(intent);
    }
}

From source file:org.alfresco.mobile.android.application.fragments.user.UserProfileFragment.java

public static void actionSendSMS(FragmentActivity activity, String number) {
    Intent sendIntent = new Intent(Intent.ACTION_VIEW);
    sendIntent.putExtra("address", number);
    sendIntent.setType("vnd.android-dir/mms-sms");
    sendIntent.putExtra("sms_body", "");

    try {/*from   w w  w. j  av a  2 s . c o m*/
        if (sendIntent.resolveActivity(activity.getPackageManager()) == null) {
            AlfrescoNotificationManager.getInstance(activity).showAlertCrouton((FragmentActivity) activity,
                    activity.getString(R.string.feature_disable));
            return;
        }
        activity.startActivity(Intent.createChooser(sendIntent, "Select SMS application."));
    } catch (ActivityNotFoundException e) {

    }
}

From source file:com.shareyourproxy.IntentLauncher.java

/**
 * View Invite friends//from ww  w  . ja v a2s  .  c  o m
 *
 * @param activity context
 */
public static void launchInviteFriendIntent(Activity activity) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, activity.getString(R.string.share_your_proxy));
    intent.putExtra(Intent.EXTRA_TEXT, activity.getString(R.string.invite_friend_content));
    if (intent.resolveActivity(activity.getPackageManager()) != null) {
        activity.startActivity(createChooser(intent, activity.getString(R.string.invite_a_friend)));
    }
}

From source file:MainActivity.java

public void takePicture(View view) {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        mLastPhotoURI = createFileURI();
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mLastPhotoURI);
        startActivityForResult(takePictureIntent, PHOTO_RESULT);
    }/*w w  w.j  a  v a 2s . c  o  m*/
}

From source file:com.master.metehan.filtereagle.ActivityMain.java

private static Intent getIntentRate(Context context) {
    Intent intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("market://details?id=" + context.getPackageName()));
    if (intent.resolveActivity(context.getPackageManager()) == null)
        intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://play.google.com/store/apps/details?id=" + context.getPackageName()));
    return intent;
}

From source file:android_network.hetnet.vpn_service.Util.java

public static void sendCrashReport(Throwable ex, final Context context) {
    if (!isPlayStoreInstall(context) || Util.isDebuggable(context))
        return;//from   w  ww  . java 2 s .  c o m

    try {
        ApplicationErrorReport report = new ApplicationErrorReport();
        report.packageName = report.processName = context.getPackageName();
        report.time = System.currentTimeMillis();
        report.type = ApplicationErrorReport.TYPE_CRASH;
        report.systemApp = false;

        ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
        crash.exceptionClassName = ex.getClass().getSimpleName();
        crash.exceptionMessage = ex.getMessage();

        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        ex.printStackTrace(printer);

        crash.stackTrace = writer.toString();

        StackTraceElement stack = ex.getStackTrace()[0];
        crash.throwClassName = stack.getClassName();
        crash.throwFileName = stack.getFileName();
        crash.throwLineNumber = stack.getLineNumber();
        crash.throwMethodName = stack.getMethodName();

        report.crashInfo = crash;

        final Intent bug = new Intent(Intent.ACTION_APP_ERROR);
        bug.putExtra(Intent.EXTRA_BUG_REPORT, report);
        bug.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (bug.resolveActivity(context.getPackageManager()) != null)
            context.startActivity(bug);
    } catch (Throwable exex) {
        Log.e(TAG, exex.toString() + "\n" + Log.getStackTraceString(exex));
    }
}

From source file:eu.faircode.adblocker.Util.java

public static void sendCrashReport(Throwable ex, final Context context) {
    if (!isPlayStoreInstall(context))
        return;/* ww  w.java  2 s  .  co m*/

    try {
        ApplicationErrorReport report = new ApplicationErrorReport();
        report.packageName = report.processName = context.getPackageName();
        report.time = System.currentTimeMillis();
        report.type = ApplicationErrorReport.TYPE_CRASH;
        report.systemApp = false;

        ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
        crash.exceptionClassName = ex.getClass().getSimpleName();
        crash.exceptionMessage = ex.getMessage();

        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        ex.printStackTrace(printer);

        crash.stackTrace = writer.toString();

        StackTraceElement stack = ex.getStackTrace()[0];
        crash.throwClassName = stack.getClassName();
        crash.throwFileName = stack.getFileName();
        crash.throwLineNumber = stack.getLineNumber();
        crash.throwMethodName = stack.getMethodName();

        report.crashInfo = crash;

        final Intent bug = new Intent(Intent.ACTION_APP_ERROR);
        bug.putExtra(Intent.EXTRA_BUG_REPORT, report);
        bug.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (bug.resolveActivity(context.getPackageManager()) != null)
            context.startActivity(bug);
    } catch (Throwable exex) {
        Log.e(TAG, exex.toString() + "\n" + Log.getStackTraceString(exex));
    }
}

From source file:org.alfresco.mobile.android.application.fragments.user.UserProfileFragment.java

public static void actionEmail(FragmentActivity activity, String email, String subject, String content) {
    if (subject == null)
        subject = "";
    if (content == null)
        content = "";

    final Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.setType("plain/text");
    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { email });
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, content);

    try {//from  w  w w. ja v  a  2  s. c  o  m
        if (emailIntent.resolveActivity(activity.getPackageManager()) == null) {
            AlfrescoNotificationManager.getInstance(activity).showAlertCrouton((FragmentActivity) activity,
                    activity.getString(R.string.feature_disable));
            return;
        }
        activity.startActivity(Intent.createChooser(emailIntent, "Select email application."));
    } catch (ActivityNotFoundException e) {

    }
}

From source file:com.vrem.wifianalyzer.navigation.items.ExportItem.java

private boolean exportAvailable(@NonNull MainActivity mainActivity, @NonNull Intent chooser) {
    return chooser.resolveActivity(mainActivity.getPackageManager()) != null;
}