Example usage for android.content Intent setData

List of usage examples for android.content Intent setData

Introduction

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

Prototype

public @NonNull Intent setData(@Nullable Uri data) 

Source Link

Document

Set the data this intent is operating on.

Usage

From source file:Main.java

public static Bitmap saveBitmapToFile(Activity activity, Bitmap bitmap) {
    String mPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
    File imageFile = new File(mPath);
    boolean create = imageFile.mkdirs();
    boolean canWrite = imageFile.canWrite();
    Calendar cal = Calendar.getInstance();
    String date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);

    String filename = null;/*from  ww  w. ja  v  a 2 s .c o  m*/
    int i = 0;
    while (imageFile.exists()) {
        i++;
        filename = date + "_mandelbrot" + i + ".png";
        imageFile = new File(mPath, filename);
        boolean canWrite2 = imageFile.canWrite();

    }

    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        /*resultB*/bitmap.compress(CompressFormat.PNG, 90, bos);
        byte[] bitmapdata = bos.toByteArray();

        //write the bytes in file
        FileOutputStream fos = new FileOutputStream(imageFile);
        fos.write(bitmapdata);
        fos.flush();
        fos.close();

        Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        intent.setData(Uri.fromFile(imageFile));
        activity.sendBroadcast(intent);

        displaySuccesToast(activity);
    } catch (FileNotFoundException e) {
        displayFileError(activity);
        e.printStackTrace();
    } catch (IOException e) {
        displayFileError(activity);
        e.printStackTrace();
    }
    return bitmap;
}

From source file:Main.java

public static void viewUriForMimeType(Context context, Uri uri, String type) {
    Intent intent;
    intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);

    if (type == null)
        intent.setData(uri);
    else/*  w ww.  j  ava2 s  . co  m*/
        intent.setDataAndType(uri, type);

    context.startActivity(intent);
}

From source file:Main.java

public static void openContactInfo(final Context context, final long contactid) {
    final Intent intent = new Intent(Intent.ACTION_VIEW);
    final Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactid));
    intent.setData(uri);
    context.startActivity(intent);/*from w ww. ja v  a2s  .  c  om*/
}

From source file:Main.java

public static void scanPhoto(Context ctx, String imgFileName) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    File file = new File(imgFileName);
    Uri contentUri = Uri.fromFile(file);
    mediaScanIntent.setData(contentUri);
    ctx.sendBroadcast(mediaScanIntent);// w w  w .ja  v  a2s .  c o  m
}

From source file:Main.java

public static Intent prepareEditContactIntent(int id) {
    Intent intent = new Intent(Intent.ACTION_EDIT, Contacts.CONTENT_URI);
    Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, id);
    intent.setData(contactUri);

    return intent;
}

From source file:Main.java

public static void uninstallApk(Context context, String packageName) {
    Intent intent = new Intent(Intent.ACTION_DELETE);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    Uri packageURI = Uri.parse("package:" + packageName);
    intent.setData(packageURI);
    context.startActivity(intent);/*from   w  ww .j av a  2s  .  com*/
}

From source file:Main.java

public static void jumpToApplicationDetail(Context context) {
    Intent localIntent = new Intent();
    localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
    localIntent.setData(Uri.fromParts("package", context.getPackageName(), null));
    context.startActivity(localIntent);//from w w  w.  j a  v  a  2s. c  om
}

From source file:Main.java

/**
 * Helper method for adding the photo to the system photo gallery so it can be accessed
 * from other apps./*from  ww  w  .  ja v a 2 s . co m*/
 *
 * @param imagePath The path of the saved image
 */
private static void galleryAddPic(Context context, String imagePath) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    File f = new File(imagePath);
    Uri contentUri = Uri.fromFile(f);
    mediaScanIntent.setData(contentUri);
    context.sendBroadcast(mediaScanIntent);
}

From source file:Main.java

public static void startInstalledAppDetailsActivity(@Nullable final Activity context) {
    if (context == null) {
        return;/*from w ww . ja v a  2 s .co  m*/
    }
    final Intent i = new Intent();
    i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    i.addCategory(Intent.CATEGORY_DEFAULT);
    i.setData(Uri.parse("package:" + context.getPackageName()));
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    context.startActivity(i);
}

From source file:Main.java

public static void openApplicationSettings(Activity activity) {
    Intent intent = new Intent();
    intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
    intent.setData(uri);
    activity.startActivity(intent);// www.  j  a va 2 s  .  c o  m
}