List of usage examples for android.content Intent resolveActivity
public ComponentName resolveActivity(@NonNull PackageManager pm)
From source file:org.alfresco.mobile.android.application.managers.ActionUtils.java
public static void actionView(FragmentActivity context, File myFile, String mimeType, ActionManagerListener listener) { Intent intent = new Intent(Intent.ACTION_VIEW); Uri data = Uri.fromFile(myFile);//from w w w . j a va2s . co m intent.setDataAndType(data, mimeType.toLowerCase()); try { if (intent.resolveActivity(context.getPackageManager()) == null) { if (listener != null) { throw new ActivityNotFoundException(); } AlfrescoNotificationManager.getInstance(context).showAlertCrouton(context, context.getString(R.string.feature_disable)); return; } context.startActivity(intent); } catch (ActivityNotFoundException e) { if (listener != null) { listener.onActivityNotFoundException(e); } } }
From source file:com.forrestguice.suntimeswidget.AlarmDialog.java
public static void scheduleAlarm(Activity context, String label, Calendar calendar) { if (calendar == null) return;// w ww. ja v a 2s . c om Calendar alarm = new GregorianCalendar(TimeZone.getDefault()); alarm.setTimeInMillis(calendar.getTimeInMillis()); int hour = alarm.get(Calendar.HOUR_OF_DAY); int minutes = alarm.get(Calendar.MINUTE); Intent alarmIntent = new Intent(AlarmClock.ACTION_SET_ALARM); alarmIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); alarmIntent.putExtra(AlarmClock.EXTRA_MESSAGE, label); alarmIntent.putExtra(AlarmClock.EXTRA_HOUR, hour); alarmIntent.putExtra(AlarmClock.EXTRA_MINUTES, minutes); if (alarmIntent.resolveActivity(context.getPackageManager()) != null) { context.startActivity(alarmIntent); } }
From source file:io.github.hidroh.materialistic.AppUtils.java
public static void openWebUrlExternal(Context context, WebItem item, String url, CustomTabsSession session) { if (!hasConnection(context)) { context.startActivity(//from w w w . ja v a 2 s. co m new Intent(context, OfflineWebActivity.class).putExtra(OfflineWebActivity.EXTRA_URL, url)); return; } Intent intent = createViewIntent(context, item, url, session); if (!HackerNewsClient.BASE_WEB_URL.contains(Uri.parse(url).getHost())) { if (intent.resolveActivity(context.getPackageManager()) != null) { context.startActivity(intent); } return; } List<ResolveInfo> activities = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); ArrayList<Intent> intents = new ArrayList<>(); for (ResolveInfo info : activities) { if (info.activityInfo.packageName.equalsIgnoreCase(context.getPackageName())) { continue; } intents.add(createViewIntent(context, item, url, session).setPackage(info.activityInfo.packageName)); } if (intents.isEmpty()) { return; } if (intents.size() == 1) { context.startActivity(intents.remove(0)); } else { context.startActivity(Intent.createChooser(intents.remove(0), context.getString(R.string.chooser_title)) .putExtra(Intent.EXTRA_INITIAL_INTENTS, intents.toArray(new Parcelable[intents.size()]))); } }
From source file:de.grobox.liberario.utils.TransportrUtils.java
static public void startGeoIntent(Context context, Location loc) { String lat = Double.toString(loc.lat / 1E6); String lon = Double.toString(loc.lon / 1E6); String uri1 = "geo:0,0?q=" + lat + "," + lon; String uri2;/* w w w. j av a 2s .c o m*/ try { uri2 = "(" + URLEncoder.encode(TransportrUtils.getLocationName(loc), "utf-8") + ")"; } catch (UnsupportedEncodingException e) { uri2 = "(" + TransportrUtils.getLocationName(loc) + ")"; } Uri geo = Uri.parse(uri1 + uri2); Log.d(context.getClass().getCanonicalName(), "Starting geo intent: " + geo.toString()); // show station on external map Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(geo); if (intent.resolveActivity(context.getPackageManager()) != null) { context.startActivity(intent); } }
From source file:org.alfresco.mobile.android.application.managers.ActionUtils.java
public static boolean actionSendMailWithAttachment(Fragment fr, String subject, String content, Uri attachment, int requestCode) { try {// ww w .java 2s . co m Intent i = new Intent(Intent.ACTION_SEND); i.putExtra(Intent.EXTRA_SUBJECT, subject); i.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(content)); i.putExtra(Intent.EXTRA_STREAM, attachment); i.setType("text/plain"); if (i.resolveActivity(fr.getActivity().getPackageManager()) == null) { AlfrescoNotificationManager.getInstance(fr.getActivity()).showAlertCrouton(fr.getActivity(), fr.getString(R.string.feature_disable)); return false; } fr.startActivityForResult(Intent.createChooser(i, fr.getString(R.string.send_email)), requestCode); return true; } catch (Exception e) { AlfrescoNotificationManager.getInstance(fr.getActivity()).showAlertCrouton(fr.getActivity(), R.string.decryption_failed); Log.d(TAG, Log.getStackTraceString(e)); } return false; }
From source file:Main.java
public static Intent getLaunchIntent(Context context, String title, String url, String sel) { Intent intent = null; String number = parseTelephoneNumber(sel); if (number != null) { intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + number)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } else {// w ww.ja va 2 s . c o m intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (isMapsURL(url)) { intent.setClassName(GMM_PACKAGE_NAME, GMM_CLASS_NAME); } else if (isYouTubeURL(url)) { intent.setPackage(YT_PACKAGE_NAME); } // Fall back if we can't resolve intent (i.e. app missing) PackageManager pm = context.getPackageManager(); if (null == intent.resolveActivity(pm)) { intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } } if (sel != null && sel.length() > 0) { ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); cm.setText(sel); } return intent; }
From source file:com.shareyourproxy.IntentLauncher.java
/** * View Whats App profile/*from w w w . j a va 2 s .co m*/ * * @param activity context * @param address whats app number */ public static void launchWhatsAppIntent(Activity activity, String address) { Intent intent = new Intent(); intent.setPackage("com.whatsapp"); intent.setData(Uri.parse("smsto:" + address)); if (intent.resolveActivity(activity.getPackageManager()) != null) { activity.startActivity(intent); } }
From source file:com.shareyourproxy.IntentLauncher.java
/** * View Address in maps/*from w w w. j a va 2 s . c o m*/ * * @param activity context * @param actionAddress location */ public static void launchAddressIntent(Activity activity, String actionAddress) { StringBuilder sb = new StringBuilder("geo:0,0?q=").append(actionAddress); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sb.toString())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (intent.resolveActivity(activity.getPackageManager()) != null) { activity.startActivity(intent); } }
From source file:com.shareyourproxy.IntentLauncher.java
/** * View Ello profile//w w w. j ava 2 s.co m * * @param activity context * @param userId ello user id */ public static void launchElloIntent(Activity activity, String userId) { StringBuilder sb = new StringBuilder("https:ello.co/").append(userId); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sb.toString())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (intent.resolveActivity(activity.getPackageManager()) != null) { activity.startActivity(intent); } }
From source file:com.shareyourproxy.IntentLauncher.java
/** * View facebook user page./*from w w w . j a v a 2s . c om*/ * * @param activity context * @param userId user profile ID */ public static void launchFacebookIntent(Activity activity, String userId) { StringBuilder sb = new StringBuilder("https:www.facebook.com/").append(userId); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sb.toString())); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (intent.resolveActivity(activity.getPackageManager()) != null) { activity.startActivity(intent); } }