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 sendMail(Context context, String dstAddr, String subject, String text) {
    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

    String[] address = { dstAddr };
    emailIntent.putExtra(Intent.EXTRA_EMAIL, address);
    emailIntent.setType("message/rfc822");
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, text);
    context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}

From source file:Main.java

public static void installApk(Context context, String filePath) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(new File(filePath)), "application/vnd.android.package-archive");
    context.startActivity(intent);/*from ww w  .  j av a 2  s.  c  om*/
}

From source file:Main.java

public static void installApk(Context context, File apkFile) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);// w  ww  .ja va  2s .c  o m
}

From source file:Main.java

static public void changeStatusIcon(Context context, int iconResID) {
    Intent intent = new Intent("at.sprinternet.odm.STATUS_CHANGED");
    intent.putExtra("statusImageID", iconResID);
    context.sendBroadcast(intent);/*w  ww. ja v a  2  s . co m*/
}

From source file:Main.java

public static void shareToOtherApp(Context context, String title, String content, String dialogTitle) {
    Intent intentItem = new Intent(Intent.ACTION_SEND);
    intentItem.setType("text/plain");
    intentItem.putExtra(Intent.EXTRA_SUBJECT, title);
    intentItem.putExtra(Intent.EXTRA_TEXT, content);
    intentItem.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(Intent.createChooser(intentItem, dialogTitle));
}

From source file:Main.java

public static void shareText(Context context, String title, String subject, String text, String mime) {
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType(mime);/*ww  w .ja v  a2  s.com*/
    share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_NEW_DOCUMENT);

    // Add data to the intent, the receiving app will decide
    // what to do with it.
    share.putExtra(Intent.EXTRA_SUBJECT, subject);
    share.putExtra(Intent.EXTRA_TEXT, text);

    context.startActivity(Intent.createChooser(share, title));
}

From source file:Main.java

public static void scanPic(Context context, File file) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    Uri contentUri = Uri.fromFile(file);
    mediaScanIntent.setData(contentUri);
    context.sendBroadcast(mediaScanIntent);
}

From source file:Main.java

public static void openPDF(Context context, String path) {
    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(path));
    intent.setDataAndType(uri, "application/pdf");
    try {/*from w ww.  j a v a  2 s  .  c o  m*/
        context.startActivity(intent);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void installAPK(String fileName, Context context) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
    context.startActivity(intent);//  ww  w  .ja va  2  s.c  om
}

From source file:Main.java

public static void goGoogleMarket(Context context) {
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse("market://search?q=" + context.getPackageName()));
    context.startActivity(i);// w w  w .  j  a  v  a 2s. co m
}