List of usage examples for android.net Uri getHost
@Nullable public abstract String getHost();
From source file:ir.keloud.android.lib.common.accounts.AccountUtils.java
/** * Restore the client cookies/*from w ww . j a v a 2 s. co m*/ * @param account * @param client * @param context */ public static void restoreCookies(Account account, KeloudClient client, Context context) { Log_OC.d(TAG, "Restoring cookies for " + account.name); // Account Manager AccountManager am = AccountManager.get(context.getApplicationContext()); Uri serverUri = (client.getBaseUri() != null) ? client.getBaseUri() : client.getWebdavUri(); String cookiesString = am.getUserData(account, Constants.KEY_COOKIES); if (cookiesString != null) { String[] cookies = cookiesString.split(";"); if (cookies.length > 0) { for (int i = 0; i < cookies.length; i++) { Cookie cookie = new Cookie(); int equalPos = cookies[i].indexOf('='); cookie.setName(cookies[i].substring(0, equalPos)); cookie.setValue(cookies[i].substring(equalPos + 1)); cookie.setDomain(serverUri.getHost()); // VERY IMPORTANT cookie.setPath(serverUri.getPath()); // VERY IMPORTANT client.getState().addCookie(cookie); } } } }
From source file:com.cerema.cloud2.lib.common.accounts.AccountUtils.java
/** * Restore the client cookies/*from w ww .jav a 2s. co m*/ * @param account * @param client * @param context */ public static void restoreCookies(Account account, OwnCloudClient client, Context context) { Log_OC.d(TAG, "Restoring cookies for " + account.name); // Account Manager AccountManager am = AccountManager.get(context.getApplicationContext()); Uri serverUri = (client.getBaseUri() != null) ? client.getBaseUri() : client.getWebdavUri(); String cookiesString = am.getUserData(account, Constants.KEY_COOKIES); if (cookiesString != null) { String[] cookies = cookiesString.split(";"); if (cookies.length > 0) { for (int i = 0; i < cookies.length; i++) { Cookie cookie = new Cookie(); int equalPos = cookies[i].indexOf('='); cookie.setName(cookies[i].substring(0, equalPos)); cookie.setValue(cookies[i].substring(equalPos + 1)); cookie.setDomain(serverUri.getHost()); // VERY IMPORTANT cookie.setPath(serverUri.getPath()); // VERY IMPORTANT client.getState().addCookie(cookie); } } } }
From source file:it.reyboz.bustorino.ActivityMain.java
/** * Try to extract the bus stop ID from a URi * * @param uri The URL/*from ww w .j ava 2 s . c om*/ * @return bus stop ID or null */ public static String getBusStopIDFromUri(Uri uri) { String busStopID; // everithing catches fire when passing null to a switch. String host = uri.getHost(); if (host == null) { Log.e("ActivityMain", "Not an URL: " + uri); return null; } switch (host) { case "m.gtt.to.it": // http://m.gtt.to.it/m/it/arrivi.jsp?n=1254 busStopID = uri.getQueryParameter("n"); if (busStopID == null) { Log.e("ActivityMain", "Expected ?n from: " + uri); } break; case "www.gtt.to.it": case "gtt.to.it": // http://www.gtt.to.it/cms/percorari/arrivi?palina=1254 busStopID = uri.getQueryParameter("palina"); if (busStopID == null) { Log.e("ActivityMain", "Expected ?palina from: " + uri); } break; default: Log.e("ActivityMain", "Unexpected intent URL: " + uri); busStopID = null; } return busStopID; }
From source file:com.google.samples.apps.iosched.util.UIUtils.java
/** * If an activity's intent is for a Google I/O web URL that the app can handle natively, this * method translates the intent to the equivalent native intent. *//* ww w .j a va2s . c om*/ public static void tryTranslateHttpIntent(Activity activity) { Intent intent = activity.getIntent(); if (intent == null) { return; } Uri uri = intent.getData(); if (uri == null || TextUtils.isEmpty(uri.getPath())) { return; } Uri sessionDetailWebUrlPrefix = Uri.parse(Config.SESSION_DETAIL_WEB_URL_PREFIX); String prefixPath = sessionDetailWebUrlPrefix.getPath(); String path = uri.getPath(); if (sessionDetailWebUrlPrefix.getScheme().equals(uri.getScheme()) && sessionDetailWebUrlPrefix.getHost().equals(uri.getHost()) && path.startsWith(prefixPath)) { String sessionId = path.substring(prefixPath.length()); activity.setIntent( new Intent(Intent.ACTION_VIEW, ScheduleContract.Sessions.buildSessionUri(sessionId))); } }
From source file:com.auth0.api.BaseAPIClient.java
public BaseAPIClient(String clientID, String baseURL, String configurationURL, String tenantName) { this.clientID = clientID; this.configurationURL = configurationURL; this.baseURL = baseURL; this.client = new AsyncHttpClient(); if (tenantName == null) { Uri uri = Uri.parse(baseURL); this.tenantName = uri.getHost(); } else {// w w w .ja v a 2s.c om this.tenantName = tenantName; } this.client .setUserAgent(String.format("%s (%s Android %s)", tenantName, Build.MODEL, Build.VERSION.RELEASE)); this.entityBuilder = new JsonEntityBuilder(new ObjectMapper()); }
From source file:com.freerdp.freerdpcore.services.LibFreeRDP.java
public static boolean setConnectionInfo(Context context, long inst, Uri openUri) { ArrayList<String> args = new ArrayList<>(); // Parse URI from query string. Same key overwrite previous one // freerdp://user@ip:port/connect?sound=&rfx=&p=password&clipboard=%2b&themes=- // Now we only support Software GDI args.add(TAG);// w w w. jav a 2 s . c o m args.add("/gdi:sw"); final String clientName = ApplicationSettingsActivity.getClientName(context); if (!clientName.isEmpty()) { args.add("/client-hostname:" + clientName); } // Parse hostname and port. Set to 'v' argument String hostname = openUri.getHost(); int port = openUri.getPort(); if (hostname != null) { hostname = hostname + ((port == -1) ? "" : (":" + String.valueOf(port))); args.add("/v:" + hostname); } String user = openUri.getUserInfo(); if (user != null) { args.add("/u:" + user); } for (String key : openUri.getQueryParameterNames()) { String value = openUri.getQueryParameter(key); if (value.isEmpty()) { // Query: key= // To freerdp argument: /key args.add("/" + key); } else if (value.equals("-") || value.equals("+")) { // Query: key=- or key=+ // To freerdp argument: -key or +key args.add(value + key); } else { // Query: key=value // To freerdp argument: /key:value if (key.equals("drive") && value.equals("sdcard")) { // Special for sdcard redirect String path = android.os.Environment.getExternalStorageDirectory().getPath(); value = "sdcard," + path; } args.add("/" + key + ":" + value); } } String[] arrayArgs = args.toArray(new String[args.size()]); return freerdp_parse_arguments(inst, arrayArgs); }
From source file:com.just.agentweb.AgentWebUtils.java
@TargetApi(19) static String getFileAbsolutePath(Activity context, Uri fileUri) { if (context == null || fileUri == null) { return null; }/* w w w .j a va2 s .c o m*/ LogUtils.i(TAG, "getAuthority:" + fileUri.getAuthority() + " getHost:" + fileUri.getHost() + " getPath:" + fileUri.getPath() + " getScheme:" + fileUri.getScheme() + " query:" + fileUri.getQuery()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, fileUri)) { if (isExternalStorageDocument(fileUri)) { String docId = DocumentsContract.getDocumentId(fileUri); String[] split = docId.split(":"); String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } } else if (isDownloadsDocument(fileUri)) { String id = DocumentsContract.getDocumentId(fileUri); Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } else if (isMediaDocument(fileUri)) { String docId = DocumentsContract.getDocumentId(fileUri); String[] split = docId.split(":"); String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } String selection = MediaStore.Images.Media._ID + "=?"; String[] selectionArgs = new String[] { split[1] }; return getDataColumn(context, contentUri, selection, selectionArgs); } else { } } // MediaStore (and general) else if (fileUri.getAuthority().equalsIgnoreCase(context.getPackageName() + ".AgentWebFileProvider")) { String path = fileUri.getPath(); int index = path.lastIndexOf("/"); return getAgentWebFilePath(context) + File.separator + path.substring(index + 1, path.length()); } else if ("content".equalsIgnoreCase(fileUri.getScheme())) { // Return the remote address if (isGooglePhotosUri(fileUri)) { return fileUri.getLastPathSegment(); } return getDataColumn(context, fileUri, null, null); } // File else if ("file".equalsIgnoreCase(fileUri.getScheme())) { return fileUri.getPath(); } return null; }
From source file:com.example.nitish.welcomapp.activitypt.ElementDetailsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { final boolean darkTheme = PreferenceUtils.getPrefDarkTheme(); setTheme(darkTheme ? R.style.DarkTheme : R.style.LightTheme); super.onCreate(savedInstanceState); ActionBarCompat.setDisplayHomeAsUpEnabled(this, true); if (savedInstanceState == null) { final Intent intent = getIntent(); Fragment fragment = null;/*from ww w. j av a 2s. c o m*/ if (intent.hasExtra(EXTRA_ATOMIC_NUMBER)) { fragment = ElementDetailsFragment.getInstance(intent.getIntExtra(EXTRA_ATOMIC_NUMBER, 0)); } else if (getIntent().getData() != null) { final Uri uri = getIntent().getData(); if (uri.getHost().equals("element")) { final String path = uri.getPathSegments().get(0); if (TextUtils.isDigitsOnly(path)) { try { fragment = ElementDetailsFragment .getInstance(Integer.parseInt(uri.getPathSegments().get(0))); } catch (NumberFormatException e) { Log.w(TAG, "Invalid atomic number"); } } else { fragment = ElementDetailsFragment.getInstance(path); } } } if (fragment != null) { getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment).commit(); } } }
From source file:com.cliqz.browser.gcm.MessageListenerService.java
/** * Create and show a simple notification containing the received GCM message. Does nothing if * the notifications are disabled in the preferences. * * @param title GCM message received.//from ww w. j av a2 s .co m * @param url url */ private void sendNewsNotification(int newType, String title, String url, String country) { if (!preferenceManager.getNewsNotificationEnabled() || country == null || !country.equals(preferenceManager.getCountryChoice().countryCode)) { return; } Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); intent.putExtra(Constants.NOTIFICATION_CLICKED, true); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Intent deleteIntent = new Intent(this, NotificationDismissedReceiver.class); PendingIntent deletePendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 0, deleteIntent, 0); final Uri uri = Uri.parse(url); final String host = uri.getHost(); final String domain = UrlUtils.getTopDomain(url); final Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); final NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(); style.bigText(title); final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_notification_news).setContentTitle(domain) .setCategory(NotificationCompat.CATEGORY_RECOMMENDATION).setContentText(title).setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent).setDeleteIntent(deletePendingIntent) .setStyle(style); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:net.i2p.android.wizard.ui.I2PDestinationFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_ADDRESSBOOK_DOMAIN) { if (resultCode == Activity.RESULT_OK) { Uri result = data.getData(); mFieldView.setText(result.getHost()); }//from ww w .ja v a 2 s.c o m } }