Example usage for android.content Intent Intent

List of usage examples for android.content Intent Intent

Introduction

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

Prototype

protected Intent(Parcel in) 

Source Link

Usage

From source file:Main.java

public static void choosePicture(Activity activity, int requestCode) {
    Intent openAlbumIntent = new Intent(Intent.ACTION_GET_CONTENT);
    openAlbumIntent.setType("image/*");
    activity.startActivityForResult(openAlbumIntent, requestCode);
}

From source file:Main.java

private static Intent getChmFileIntent(String filePath) {

    Intent intent = new Intent("android.intent.action.VIEW");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    Uri uri = Uri.fromFile(new File(filePath));
    intent.setDataAndType(uri, "application/x-chm");
    return intent;
}

From source file:Main.java

public static void share(Context context, String title, String url) {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, url);
    Intent chooserIntent = Intent.createChooser(shareIntent, title);
    chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(chooserIntent);
}

From source file:Main.java

public static Intent newSendToIntent(String emailAddress, String subject, String contentBody) {
    return new Intent(Intent.ACTION_SENDTO).setData(Uri.parse("mailto:" + Uri.encode(emailAddress) + "?subject="
            + Uri.encode(subject) + "&body=" + Uri.encode(contentBody)));
}

From source file:Main.java

public static Intent buildCaptureIntent(Uri uri) {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
    return intent;
}

From source file:Main.java

public static void imitateHome(Context context) {
    try {/* ww  w.j a va 2  s .c  o m*/
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addCategory(Intent.CATEGORY_HOME);
        context.startActivity(intent);
    } catch (Exception e) {
        // TODO: handle exception
    }
}

From source file:Main.java

public static void sendSMS(final Context context, String message) {
    final Intent sendIntent = new Intent(Intent.ACTION_VIEW);
    sendIntent.putExtra("sms_body", message);
    sendIntent.setType("vnd.android-dir/mms-sms");
    context.startActivity(sendIntent);/*from w  w w  .j a  va 2 s  . c o m*/
}

From source file:Main.java

private static Intent getWordFileIntent(String filePath) {

    Intent intent = new Intent("android.intent.action.VIEW");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    Uri uri = Uri.fromFile(new File(filePath));
    intent.setDataAndType(uri, "application/msword");
    return intent;
}

From source file:Main.java

public static void takeMyselfToForeground(Context context, Class launcher) {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setClass(context, launcher);/*from  ww w  .j a  v  a 2s  . c om*/
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    context.startActivity(intent);
}

From source file:Main.java

private static Intent getExcelFileIntent(String filePath) {

    Intent intent = new Intent("android.intent.action.VIEW");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    Uri uri = Uri.fromFile(new File(filePath));
    intent.setDataAndType(uri, "application/vnd.ms-excel");
    return intent;
}