List of usage examples for android.content Intent setData
public @NonNull Intent setData(@Nullable Uri data)
From source file:Main.java
static Intent createOpenCalendarAtDayIntent(Context context, DateTime goToTime) { Intent launchIntent = createCalendarIntent(Intent.ACTION_VIEW); Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon(); builder.appendPath(TIME);/*from ww w.j ava 2 s .c om*/ if (goToTime.getMillis() != 0) { launchIntent.putExtra(KEY_DETAIL_VIEW, true); ContentUris.appendId(builder, goToTime.getMillis()); } launchIntent.setData(builder.build()); return launchIntent; }
From source file:com.nit.vicky.servicelayer.NoteService.java
/** * Considering the field is new, if it has media handle it * //from w ww .j a va 2 s.co m * @param field */ private static void importMediaToDirectory(IField field, Context context) { String tmpMediaPath = null; switch (field.getType()) { case AUDIO: tmpMediaPath = field.getAudioPath(); break; case IMAGE: tmpMediaPath = field.getImagePath(); break; case TEXT: default: break; } if (tmpMediaPath != null) { try { File inFile = new File(tmpMediaPath); if (inFile.exists()) { Collection col = AnkiDroidApp.getCol(); String mediaDir = col.getMedia().getDir() + "/"; File mediaDirFile = new File(mediaDir); File parent = inFile.getParentFile(); // If already there. if (mediaDirFile.getAbsolutePath().contentEquals(parent.getAbsolutePath())) { return; } //File outFile = new File(mediaDir + inFile.getName().replaceAll(" ", "_")); //if (outFile.exists()) { File outFile = null; if (field.getType() == EFieldType.IMAGE) { outFile = File.createTempFile("imggallery", ".jpg", DiskUtil.getStoringDirectory()); } else if (field.getType() == EFieldType.AUDIO) { outFile = File.createTempFile("soundgallery", ".mp3", DiskUtil.getStoringDirectory()); } //} if (field.hasTemporaryMedia()) { // Move inFile.renameTo(outFile); } else { // Copy InputStream in = new FileInputStream(tmpMediaPath); OutputStream out = new FileOutputStream(outFile.getAbsolutePath()); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); } switch (field.getType()) { case AUDIO: field.setAudioPath(outFile.getAbsolutePath()); break; case IMAGE: field.setImagePath(outFile.getAbsolutePath()); break; default: break; } Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); scanIntent.setData(Uri.fromFile(inFile)); context.sendBroadcast(scanIntent); } } catch (IOException e) { throw new RuntimeException(e); } } }
From source file:im.delight.android.commons.Social.java
/** * Displays an application chooser and composes the described email using the selected application * * @param recipientEmail the recipient's email address * @param subjectText the subject line of the message * @param bodyText the body text of the message * @param captionRes a string resource ID for the title of the application chooser's window * @param restrictToPackage an application's package name to restricted the selection to * @param context a context reference//from w w w . j av a 2 s. com * @throws Exception if there was an error trying to launch the email application */ public static void sendMail(final String recipientEmail, final String subjectText, final String bodyText, final int captionRes, final String restrictToPackage, final Context context) throws Exception { final String uriString = "mailto:" + Uri.encode(recipientEmail) + "?subject=" + Uri.encode(subjectText) + "&body=" + Uri.encode(bodyText); final Uri uri = Uri.parse(uriString); final Intent emailIntent = new Intent(Intent.ACTION_SENDTO); emailIntent.setData(uri); if (restrictToPackage != null && restrictToPackage.length() > 0) { emailIntent.setPackage(restrictToPackage); if (context != null) { // launch the target app directly context.startActivity(emailIntent); } } else { if (context != null) { // offer a selection of all applications that can handle the email Intent context.startActivity(Intent.createChooser(emailIntent, context.getString(captionRes))); } } }
From source file:im.delight.android.baselib.Social.java
/** * Constructs an SMS Intent for the given message details and opens the application chooser for this Intent * * @param recipient the recipient's phone number or `null` * @param body the body of the message/*from w w w .j a v a 2 s .co m*/ * @param captionRes the string resource ID for the application chooser's window title * @param context the Context instance to start the Intent from * @throws Exception if there was an error trying to launch the SMS Intent */ public static void sendSMS(final String recipient, final String body, final int captionRes, final Context context) throws Exception { final Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setType(HTTP.PLAIN_TEXT_TYPE); if (recipient != null && recipient.length() > 0) { intent.setData(Uri.parse("smsto:" + recipient)); } else { intent.setData(Uri.parse("sms:")); } intent.putExtra("sms_body", body); intent.putExtra(Intent.EXTRA_TEXT, body); if (context != null) { // offer a selection of all applications that can handle the SMS Intent context.startActivity(Intent.createChooser(intent, context.getString(captionRes))); } }
From source file:Main.java
/** Google calendar intent variant 1 */ private static Intent constructGoogleCalendarIntentVariant2() { final Intent intent = new Intent(); // Newer calendar have API for launching the google calendar. See documentation at: // http://developer.android.com/guide/topics/providers/calendar-provider.html#intents final long startTimeMillis = System.currentTimeMillis(); final String url = "content://com.android.calendar/time/" + startTimeMillis; intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); return intent; }
From source file:com.bt.download.android.gui.util.UIUtils.java
public static void openURL(Context context, String url) { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); context.startActivity(i);/* ww w . ja v a 2 s .c om*/ }
From source file:im.delight.android.commons.Social.java
/** * Displays an application chooser and composes the described text message (SMS) using the selected application * * @param recipientPhone the recipient's phone number or `null` * @param bodyText the body text of the message * @param captionRes a string resource ID for the title of the application chooser's window * @param context a context reference//from w w w . java 2 s .c o m * @throws Exception if there was an error trying to launch the SMS application */ public static void sendSms(final String recipientPhone, final String bodyText, final int captionRes, final Context context) throws Exception { final Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setType(HTTP.PLAIN_TEXT_TYPE); if (recipientPhone != null && recipientPhone.length() > 0) { intent.setData(Uri.parse("smsto:" + recipientPhone)); } else { intent.setData(Uri.parse("sms:")); } intent.putExtra("sms_body", bodyText); intent.putExtra(Intent.EXTRA_TEXT, bodyText); if (context != null) { // offer a selection of all applications that can handle the SMS Intent context.startActivity(Intent.createChooser(intent, context.getString(captionRes))); } }
From source file:com.frostwire.android.gui.util.UIUtils.java
public static void openURL(Context context, String url) { try {/*w ww . j a v a 2s . co m*/ Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); context.startActivity(i); } catch (ActivityNotFoundException e) { e.printStackTrace(); // ignore // yes, it happens } }
From source file:com.rsegismont.androlife.core.utils.AndrolifeUtils.java
public static void openAndrolifeCoreSettings(Context context) { if (Build.VERSION.SDK_INT >= 9) { try {/*from www .jav a2 s. c om*/ // Open the specific App Info page: final Intent intent = AndrolifeApi9.getSettingsIntent(); intent.setData(Uri.parse("package:" + androlifeCore)); context.startActivity(intent); } catch (ActivityNotFoundException e) { // e.printStackTrace(); Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS); context.startActivity(intent); } } else { Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS); context.startActivity(intent); } }
From source file:com.xiaomi.account.utils.SysHelper.java
public static void getbackPassword(Activity activity) { Intent intent = new Intent("android.intent.action.VIEW"); intent.setData(Uri.parse(com.xiaomi.account.Constants.PASSWORD_RECOVERY_URL)); intent.addFlags(67108864);//from w ww . j a va 2 s . c o m intent.addFlags(268435456); intent.addFlags(8388608); activity.startActivity(intent); }