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

/**
 * This method queries the system to check if there is a viewer available or not. If no suitable viewer is
 * found, this method returns false./*from w w w  . j  a  v a  2 s .com*/
 * @return True if PDF viewer is available, false otherwise.
 */
public static boolean isViewerAvailable(Context context, Uri uri) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(uri);
    final List<ResolveInfo> list = packageManager.queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

From source file:Main.java

public static void shareViaSms(Context context, String subject, String text) {
    Intent intent = new Intent();
    intent.setType("text/plain");
    intent.setData(Uri.parse("sms:"));
    intent.setAction(Intent.ACTION_VIEW);
    intent.putExtra("sms_body", text);
    context.startActivity(Intent.createChooser(intent, "Share via SMS"));
}

From source file:Main.java

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

    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

/**
 * Open Calendar app with specific time// ww w.ja va  2s.c o m
 */
public static void openCalendar(Activity activity, long epochEventStartTime) {
    Uri uri = Uri.parse("content://com.android.calendar/time/" + epochEventStartTime);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(uri);
    intent.putExtra("VIEW", "DAY");
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    activity.startActivity(intent);
}

From source file:Main.java

public static void chooserSysPics(Context context, int requestCode) {
    if (context == null) {
        return;/*  w w  w .jav  a 2 s . c o m*/
    }

    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

/**
 * Opens market detail application page for donate app
 * // w  ww.j  av  a 2 s .c  om
 * @param context application context
 */
public static void gotoDonate(Context context) {
    Intent marketIntent = new Intent(Intent.ACTION_VIEW);
    marketIntent.setData(Uri.parse("market://details?id=ru.neverdark.phototoolsdonate"));
    context.startActivity(marketIntent);
}

From source file:Main.java

public static void sendIntent(Context context, Uri uri) {
    Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    intent.setData(uri);
    context.sendBroadcast(intent);//from  w w  w  .  ja va  2s .c  om
}

From source file:Main.java

public static Intent createOpenCalendarEventIntent(int eventId, DateTime from, DateTime to) {
    Intent intent = createCalendarIntent(Intent.ACTION_VIEW);
    intent.setData(ContentUris.withAppendedId(Events.CONTENT_URI, eventId));
    intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, from.getMillis());
    intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, to.getMillis());
    return intent;
}

From source file:Main.java

public static void dialIn(Context context, String number) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_DIAL);
    intent.setData(Uri.parse("tel://" + number));
    context.startActivity(intent);// w ww . j  a  va  2 s.  c om
}

From source file:Main.java

/**
 * Get the intent used to open installation U.I.
 *
 * @param fileUri downloaded file URI from the download manager.
 * @return intent to open installation U.I.
 */// w  w w. ja  v  a 2 s  . c o m
@NonNull
static Intent getInstallIntent(Uri fileUri) {
    Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
    intent.setData(fileUri);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    return intent;
}