final Context context = ... // whereever your context is CharSequence sequence = Html.fromSource(context.getString(R.string.clickable_string)); SpannableStringBuilder strBuilder = new SpannableStringBuilder(sequence); UnderlineSpan[] underlines = strBuilder.getSpans(UnderlineSpan.class); for(UnderlineSpan span : underlines) { int start = strBuilder.getSpanStart(span); int end = strBuilder.getSpanEnd(span); int flags = strBuilder.getSpanFlags(span); ClickableSpan myActivityLauncher = new ClickableSpan() { public void onClick(View view) { context.startActivity(getIntentForActivityToStart()); } }; strBuilder.setSpan(myActivityLauncher, start, end, flags); } TextView textView = ... textView.setText(strBuilder); textView.setMovementMethod(LinkMovementMethod.getInstance());
public class ExternalReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.i("ExternalReceiver","onReceive"); Bundle extras = intent.getExtras(); StringBuilder payload = new StringBuilder(); for(String key : extras.keySet()){ payload.append(String.format("%s=%s", key, extras.getString(key)) + '\n'); } Intent newIntent = new Intent(); newIntent.setClass(context, AndroidMobilePushApp.class); newIntent.putExtra(context.getString(R.string.msg_field), payload.toString()); newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); context.startActivity(newIntent); } }
public static void goToMarket(Context context){ Intent it = new Intent(Intent.ACTION_VIEW); it.setData(Uri.parse(context.getString(R.string.playstorelink))); context.startActivity(it); }
public static void StartEmailIntent (Context cx, String EmailAddress){ Intent email = new Intent(Intent.ACTION_SEND); email.setType("plain/text"); email.putExtra(Intent.EXTRA_EMAIL, new String[]{EmailAddress}); cx.startActivity(Intent.createChooser(email, cx.getString(R.string.dlg_sendmail_selectortitle))); }
public static void shareImageFileWithIntent(File imageFile, Context context) { MimeTypeMap mime = MimeTypeMap.getSingleton(); String type = mime.getMimeTypeFromExtension("jpg"); Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType(type); sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(imageFile)); sharingIntent.putExtra(Intent.EXTRA_TEXT, "your extra text"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "your subject"); context.startActivity(Intent.createChooser(sharingIntent, context.getString(R.string.share_image_intent))); }
public static void shareMultiple(List<File> files, Context context){ ArrayList<Uri> uris = new ArrayList<>(); for(File file: files){ uris.add(Uri.fromFile(file)); } final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); intent.setType("*/*"); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); context.startActivity(Intent.createChooser(intent, context.getString(R.string.ids_msg_share))); }
public static void attachFileviaEmail(Context p_context,String p_subject,String p_filePath) { Uri m_uri; File m_file = new File(p_filePath); String m_emailTo = "Receiver Email ID"; if(m_file.exists()) { final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("plain/text"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{m_emailTo}); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, p_subject); m_uri = Uri.parse("file://" + p_filePath); if(m_uri != null) { emailIntent.putExtra(Intent.EXTRA_STREAM, m_uri); } // emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Hi pl find attachment....."); p_context.startActivity(Intent.createChooser(emailIntent, p_context.getString(R.string.lbl_send_email))); } }
public static void writeReviewMail(Context context) { Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts( "mailto", "youremail@example.com", null)); emailIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.yoursubject)); context.startActivity(Intent.createChooser(emailIntent, context.getString(R.string.contact_us))); }
public static void sendEmailWithImages(Context context, String emailTo, String emailCC, String subject, String emailText, String type, List<String> filePaths) { //need to "send multiple" to get more than one attachment final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); emailIntent.setType(type); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{emailTo}); emailIntent.putExtra(android.content.Intent.EXTRA_CC, new String[]{emailCC}); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailText); //has to be an ArrayList ArrayList<Uri> uris = new ArrayList<Uri>(); //convert from paths to Android friendly Parcelable Uri's if(filePaths != null) { for (String file : filePaths) { File fileIn = new File(file); Uri u = Uri.fromFile(fileIn); uris.add(u); } emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); } try { context.startActivity(Intent.createChooser(emailIntent, context.getString(R.string.send_email_using_message))); }catch (ActivityNotFoundException e) { //TODO } }
final Uri uri = Uri.parse(ctx.getString(resOnlineUrl)); final Intent intent = new Intent(Intent.ACTION_VIEW, uri); ctx.startActivity(intent);
context.startActivity(i); ((Activity)context).finish(); }else{
updateIntent(launchIntent); mContext.startActivity(launchIntent);