Example usage for android.content Intent setDataAndType

List of usage examples for android.content Intent setDataAndType

Introduction

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

Prototype

public @NonNull Intent setDataAndType(@Nullable Uri data, @Nullable String type) 

Source Link

Document

(Usually optional) Set the data for the intent along with an explicit MIME data type.

Usage

From source file:Main.java

public static void instanll(File file, Context context) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    context.startActivity(intent);//from w ww.  j a v a2  s.c  o m
}

From source file:Main.java

public static void installApp(Context context, File apkFile) {
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");

    context.startActivity(intent);//from  w  w  w  .j  a  v  a 2s.  co m
    // YxCfgManager.getYxCfgInstance().write(YxAppCfg.IS_FIRST, true);
}

From source file:Main.java

public static void installApk(Context context, File file) {
    if (context == null)
        return;/*from  w  w  w .  j  a  v  a  2 s .c  o  m*/
    if (file == null)
        return;
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    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 installApk(Context context, Uri file) {
    if (context == null)
        return;/*  w  w w  .  jav a2 s .co m*/
    if (file == null)
        return;
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(file, "application/vnd.android.package-archive");
    context.startActivity(intent);
}

From source file:Main.java

public static void installApk(Context context, String filePath) {
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(new File(filePath)), "application/vnd.android.package-archive");
    context.startActivity(intent);//from   w w w.  j  a  va 2s .com
}

From source file:Main.java

public static void install(Activity activity, File apkFile) {
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
    activity.startActivity(intent);/*  ww w .j  av  a 2s  .c  o  m*/
}

From source file:Main.java

public static void Instanll(File file, Context context) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    context.startActivity(intent);// ww  w  . ja v  a  2  s .co  m
}

From source file:Main.java

/**
 * Save a media in the downloads directory and offer to open it with a third party application.
 * @param activity the activity/*from   www  . jav a2 s . c  o m*/
 * @param savedMediaPath the media path
 * @param mimeType the media mime type.
 */
public static void openMedia(final Activity activity, final String savedMediaPath, final String mimeType) {
    if ((null != activity) && (null != savedMediaPath)) {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                try {
                    File file = new File(savedMediaPath);
                    Intent intent = new Intent();
                    intent.setAction(android.content.Intent.ACTION_VIEW);
                    intent.setDataAndType(Uri.fromFile(file), mimeType);
                    activity.startActivity(intent);
                } catch (ActivityNotFoundException e) {
                    Toast.makeText(activity, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
                } catch (Exception e) {
                }
            }
        });
    }
}

From source file:Main.java

private static void syncContactHiResPhoto(Context context, long rawContactId) {
    final String serviceName = "com.google.android.syncadapters.contacts." + "SyncHighResPhotoIntentService";
    final String servicePackageName = "com.google.android.syncadapters.contacts";
    final Uri uri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
    final Intent intent = new Intent();
    intent.setClassName(servicePackageName, serviceName);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(uri, RawContacts.CONTENT_ITEM_TYPE);
    try {/*w w  w . j  a v  a 2  s .  c  o m*/
        context.startService(intent);
    } catch (Exception e) {

    }
}

From source file:Main.java

public static Intent getImageFileIntent(File file) {
    Intent intent = new Intent("android.intent.action.VIEW");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.fromFile(file), "image/*");
    return intent;
}