Example usage for android.content Intent setType

List of usage examples for android.content Intent setType

Introduction

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

Prototype

public @NonNull Intent setType(@Nullable String type) 

Source Link

Document

Set an explicit MIME data type.

Usage

From source file:Main.java

/**
 * send a message  to call the emergency with location of the accident
 *
 * @param latitude//from  w ww .  j ava  2s .c  om
 * @param longitude
 */
public static void sendEmergencyToMessages(double latitude, double longitude, Context context) {
    Intent sendSmsIntent = new Intent(Intent.ACTION_VIEW);
    sendSmsIntent.setData(Uri.parse("sms:"));
    sendSmsIntent.setType("vnd.android-dir/mms-sms");
    String message = "The Car had accident at: " + latitude + " , " + longitude;
    sendSmsIntent.putExtra(Intent.EXTRA_TEXT, message);
    if (sendSmsIntent.resolveActivity(context.getPackageManager()) != null) {
        context.startActivity(sendSmsIntent);
    }
}

From source file:Main.java

public static Intent getSmsIntent() {
    Intent conversations = new Intent(Intent.ACTION_MAIN);
    //conversations.addCategory(Intent.CATEGORY_DEFAULT);
    conversations.setType(SMS_MIME_TYPE);
    // should I be using FLAG_ACTIVITY_RESET_TASK_IF_NEEDED??
    int flags = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP
            | Intent.FLAG_ACTIVITY_CLEAR_TOP;
    conversations.setFlags(flags);//www.j a  va 2 s .c  o  m

    return conversations;
}

From source file:Main.java

public static void shareImage(Context context, Uri uri, String title) {
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
    shareIntent.setType("image/jpeg");
    context.startActivity(Intent.createChooser(shareIntent, title));
}

From source file:Main.java

public static void composeSms(Context context, String phoneNumber, String smsBody) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.putExtra("sms_body", smsBody);
    intent.putExtra("address", phoneNumber);
    intent.setType("vnd.android-dir/mms-sms");
    context.startActivity(intent);//from w  w w  .j a  v  a 2  s.  c o m
}

From source file:Main.java

public static void choosePicFromGalley(Context context) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);//ACTION_OPEN_DOCUMENT
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("image/jpeg");

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
        ((Activity) context).startActivityForResult(intent, CHOOSE_GALLERY);
    } else {/*  w w  w.  j a v  a2 s.  c  om*/
        ((Activity) context).startActivityForResult(intent, CHOOSE_GALLERY);
    }
}

From source file:Main.java

public static void sharePic(Uri uri, String desc, Context context) {

    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
    shareIntent.setType("image/jpeg");
    context.startActivity(Intent.createChooser(shareIntent, desc));
}

From source file:Main.java

public static void chooserPics(Context context, int requestCode) {
    if (context == null) {
        return;//from   ww w  .  j  a  v a2  s .c o  m
    }

    try {
        Intent localIntent = new Intent();
        localIntent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        localIntent.setType("image/*");
        localIntent.setAction(Intent.ACTION_GET_CONTENT);
        if (context instanceof Activity) {
            ((Activity) context).startActivityForResult(Intent.createChooser(localIntent, "Select Picture"),
                    requestCode);
        } else {
            localIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(Intent.createChooser(localIntent, "Select Picture"));
        }
    } catch (Exception e) {
    }
}

From source file:Main.java

public static void chooserSysPics(Context context, int requestCode) {
    if (context == null) {
        return;// w  w  w  .ja  v a2  s .com
    }

    try {
        Intent localIntent = new Intent();
        localIntent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        localIntent.setType("image/*");
        // Intent.ACTION_GET_CONTENT
        localIntent.setAction("android.intent.action.GET_CONTENT");
        if (context instanceof Activity) {
            ((Activity) context).startActivityForResult(localIntent, requestCode);
        } else {
            localIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(localIntent);
        }
    } catch (Exception e) {
    }
}

From source file:Main.java

public static void choiceAvatarFromGalleryWithCrop(Activity context) {

    Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    intent.setType("image/*");
    //intent.setAction(Intent.ACTION_GET_CONTENT);
    context.startActivityForResult(intent, SELECT_IMAGE_GALLERY_REQUEST_CODE);
    //if (Build.VERSION.SDK_INT < 19) {
    //            Intent intentPikc = new Intent();
    //            intentPikc.setType("image/*");
    //            intentPikc.setAction(Intent.ACTION_GET_CONTENT);
    //            context.startActivityForResult(intentPikc, SELECT_IMAGE_GALLERY_REQUEST_CODE);
    //        } else {
    //            Intent intentKitKat = new Intent(Intent.ACTION_GET_CONTENT);
    //            intentKitKat.setType("image/*");
    //            context.startActivityForResult(intentKitKat, SELECT_KITKAT_IMAGE_GALLERY_REQUEST_CODE);
    //        }// ww w  . java2s.  c o  m

    //        Intent intent = new Intent();
    //        intent.setType("image/*");
    //        Intent intent = new Intent(
    //                Intent.ACTION_GET_CONTENT,
    //                MediaStore.Images.Media.INTERNAL_CONTENT_URI);
    //        intent.setType("image/*");
    ////        Intent intent = new Intent(Intent.ACTION_PICK,
    ////                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    ////        intent.setAction(Intent.ACTION_GET_CONTENT);
    //        context.startActivityForResult(intent, SELECT_IMAGE_GALLERY_REQUEST_CODE);

    //        Intent intent = new Intent();
    //        intent.setType("image/*");
    //        intent.setAction(Intent.ACTION_GET_CONTENT);
    //        context.startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_IMAGE_GALLERY_REQUEST_CODE);
}

From source file:Main.java

public static void shareApkInfo(String info, Context context) {
    Intent intent = new Intent();
    intent.setAction("android.intent.action.SEND");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, info);
    context.startActivity(intent);//from www.  j  av a2 s .  c o m
}