Example usage for android.content Context startActivity

List of usage examples for android.content Context startActivity

Introduction

In this page you can find the example usage for android.content Context startActivity.

Prototype

public abstract void startActivity(@RequiresPermission Intent intent);

Source Link

Document

Same as #startActivity(Intent,Bundle) with no options specified.

Usage

From source file:Main.java

/**
 * <pre>/*from ww  w. j a  v a 2  s .c o m*/
 * Open other app to view URL of an app (typically browser or Google Play)
 * </pre>
 * @param downloadUrl
 */
public static void openDownloadPage(String downloadUrl) {
    Context context = getCurrentContext();
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setData(Uri.parse(downloadUrl));
    context.startActivity(intent);
}

From source file:Main.java

public static void startInstall(Context context, Uri uri) {
    Intent install = new Intent(Intent.ACTION_VIEW);
    install.setDataAndType(uri, "application/vnd.android.package-archive");
    install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(install);
}

From source file:Main.java

/**
 * call system to install the APK file//from w w  w.j ava 2s  .c o m
 * */
public static void installAPKFile(Context context, File file) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    context.startActivity(intent);
}

From source file:Main.java

public static void goDial(Context context, String dial_number) {
    Intent phonepassIntent = new Intent();
    phonepassIntent.setAction(Intent.ACTION_DIAL);
    phonepassIntent.setData(Uri.parse("tel:" + dial_number));
    context.startActivity(phonepassIntent);
}

From source file:Main.java

/**
 * Goes back to the specific activity if it was already created and clears stack
 * on top of it/*from  w ww  .j ava  2s  .  co  m*/
 * @param context context to work in
 * @param activityToGoBack activity class to go back to
 */
public static void goBackTo(Context context, Class<? extends Activity> activityToGoBack) {
    Intent intent = new Intent(context, activityToGoBack);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    context.startActivity(intent);
}

From source file:Main.java

public static void forward(Context context, String body) {
    if (body != null) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, body);
        context.startActivity(intent);
    }/*from   w ww .  j  a v a2  s .  c o m*/
}

From source file:Main.java

public static void launchApp(Context context, String packageName) {
    PackageManager packageManager = context.getPackageManager();
    Intent intent = packageManager.getLaunchIntentForPackage(packageName);
    if (intent != null) {
        context.startActivity(intent);
    }//ww  w  . j a  va  2s.  co m
}

From source file:Main.java

public static boolean installApp(Context context, File apkFile) {
    try {/*from  w ww .j  a  v a  2  s .  co m*/
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
        context.startActivity(intent);
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:Main.java

public static void dialPhone(Context context, String phoneNumber) {
    if (!TextUtils.isEmpty(phoneNumber)) {
        try {/*from   ww w  .j  a  v a 2s  . co m*/
            Intent callIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNumber));
            context.startActivity(callIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

public static void callPhone(Context context, String phoneNumber) {
    if (!TextUtils.isEmpty(phoneNumber)) {
        try {//from  www  .  j av  a  2  s. c om
            Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber));
            context.startActivity(callIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}