List of usage examples for android.net Uri getAuthority
@Nullable public abstract String getAuthority();
From source file:org.coocood.vcontentprovider.VContentProvider.java
@Override public String getType(Uri uri) { String table = getTableName(uri); String idPath = getIdPath(uri); return "vnd.android.cursor." + idPath == null ? "dir" : "item" + "/vnd." + uri.getAuthority() + "." + table; }
From source file:com.synox.android.ui.activity.ShareActivity.java
@Override protected void onNewIntent(Intent intent) { // Verify the action and get the query if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); Log_OC.w(TAG, "Ignored Intent requesting to query for " + query); } else if (UsersAndGroupsSearchProvider.ACTION_SHARE_WITH.equals(intent.getAction())) { Uri data = intent.getData(); String dataString = intent.getDataString(); String shareWith = dataString.substring(dataString.lastIndexOf('/') + 1); doShareWith(shareWith, UsersAndGroupsSearchProvider.DATA_GROUP.equals(data.getAuthority())); } else {/* ww w. ja v a2 s. c om*/ Log_OC.wtf(TAG, "Unexpected intent " + intent.toString()); } }
From source file:com.morphoss.acal.service.UpdateTimezones.java
private void refreshTimezoneData() { try {/*from w ww. ja v a 2s.com*/ HashMap<String, Long> currentZones = new HashMap<String, Long>(); HashMap<String, Long> updatedZones = new HashMap<String, Long>(); HashMap<String, Long> insertedZones = new HashMap<String, Long>(); Cursor allZones = cr.query(Timezones.CONTENT_URI, new String[] { Timezones.TZID, Timezones.LAST_MODIFIED }, null, null, null); Long maxModified = 0L; for (allZones.moveToFirst(); !allZones.isAfterLast(); allZones.moveToNext()) { if (Constants.LOG_VERBOSE) Log.println(Constants.LOGV, TAG, "Found existing zone of '" + allZones.getString(0) + "' modified: " + AcalDateTime.fromMillis(allZones.getLong(1) * 1000L).toString()); currentZones.put(allZones.getString(0), allZones.getLong(1)); if (allZones.getLong(1) > maxModified) maxModified = allZones.getLong(1); } AcalDateTime mostRecentChange = AcalDateTime.getUTCInstance().setEpoch(maxModified); Log.println(Constants.LOGI, TAG, "Found " + allZones.getCount() + " existing timezones, most recent change on " + mostRecentChange.toString()); if (allZones.getCount() > 350 && mostRecentChange.after(AcalDateTime.getUTCInstance().addDays(-30))) { Log.println(Constants.LOGI, TAG, "Skipping update - our database is pretty recent"); return; } requestor.interpretUriString(tzUrl("list", null)); JSONObject root = requestor.doJsonRequest("GET", null, null, null); if (requestor.wasRedirected()) { Uri tzUri = Uri.parse(requestor.fullUrl()); String redirectedUrl = tzUri.getScheme() + "://" + tzUri.getAuthority() + tzUri.getPath(); if (Constants.debugTimeZone && Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, "Redirected to Timezone Server at " + redirectedUrl); tzServerBaseUrl = redirectedUrl; AcalApplication.setPreferenceString(PrefNames.tzServerBaseUrl, redirectedUrl); } if (requestor.getStatusCode() >= 399) { Log.println(Constants.LOGI, TAG, "Bad response " + requestor.getStatusCode() + " from Timezone Server at " + tzUrl("list", null)); } if (root == null) { Log.println(Constants.LOGI, TAG, "No JSON from GET " + tzUrl("list", null)); return; } String tzid; String tzData = ""; long lastModified; StringBuilder localNames; StringBuilder aliases; ContentValues zoneValues = new ContentValues(); String tzDateStamp = root.getString("dtstamp"); JSONArray tzArray = root.getJSONArray("timezones"); for (int i = 0; i < tzArray.length(); i++) { JSONObject zoneNode = tzArray.getJSONObject(i); tzid = zoneNode.getString("tzid"); if (updatedZones.containsKey(tzid) || insertedZones.containsKey(tzid)) continue; if (Constants.debugTimeZone && Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, "Working on " + tzid); lastModified = AcalDateTime.fromString(zoneNode.getString("last-modified")).getEpoch(); if (currentZones.containsKey(tzid) && currentZones.get(tzid) <= lastModified) { currentZones.remove(tzid); continue; } tzData = getTimeZone(tzid); if (tzData == null) continue; localNames = new StringBuilder(); try { JSONArray nameNodes = zoneNode.getJSONArray("local_names"); for (int j = 0; j < nameNodes.length(); j++) { if (localNames.length() > 0) localNames.append("\n"); localNames.append(nameNodes.getJSONObject(j).getString("lang")).append('~') .append(nameNodes.getJSONObject(j).getString("lname")); } } catch (JSONException je) { } aliases = new StringBuilder(); try { JSONArray aliasNodes = zoneNode.getJSONArray("aliases"); for (int j = 0; j < aliasNodes.length(); j++) { if (aliases.length() > 0) aliases.append("\n"); aliases.append(aliasNodes.getString(j)); } } catch (JSONException je) { } zoneValues.put(Timezones.TZID, tzid); zoneValues.put(Timezones.ZONE_DATA, tzData); zoneValues.put(Timezones.LAST_MODIFIED, lastModified); zoneValues.put(Timezones.TZ_NAMES, localNames.toString()); zoneValues.put(Timezones.TZID_ALIASES, aliases.toString()); Uri tzUri = Uri.withAppendedPath(Timezones.CONTENT_URI, "tzid/" + StaticHelpers.urlescape(tzid, false)); if (currentZones.containsKey(tzid)) { if (cr.update(tzUri, zoneValues, null, null) != 1) { Log.e(TAG, "Failed update for TZID '" + tzid + "'"); } updatedZones.put(tzid, currentZones.get(tzid)); currentZones.remove(tzid); } else { if (cr.insert(tzUri, zoneValues) == null) Log.e(TAG, "Failed insert for TZID '" + tzid + "'"); insertedZones.put(tzid, currentZones.get(tzid)); } if (context.workWaiting()) { Log.println(Constants.LOGI, TAG, "Something is waiting - deferring timezone sync until later."); deferMe = true; break; } // Let other stuff have a chance Thread.sleep(350); } int removed = 0; if (currentZones.size() > 0) { StringBuilder s = new StringBuilder(); for (String tz : currentZones.keySet()) { if (s.length() > 0) s.append(','); s.append("'").append(tz).append("'"); } removed = cr.delete(Timezones.CONTENT_URI, Timezones.TZID + " IN (" + s + ")", null); } Log.println(Constants.LOGI, TAG, "Updated data for " + updatedZones.size() + " zones, added data for " + insertedZones.size() + " new zones, removed data for " + removed); } catch (Exception e) { Log.e(TAG, Log.getStackTraceString(e)); } }
From source file:org.peterbaldwin.vlcremote.net.MediaServer.java
public MediaServer(Context context, Uri data) { mContext = context; mAuthority = data.getAuthority(); }
From source file:com.android.messaging.FakeContentProvider.java
public FakeContentProvider(final Context context, final Uri uri, final boolean canDelegate) { mGlobalContext = context;//w w w. ja v a2s. c o m mUri = uri; if (canDelegate) { mProvider = mGlobalContext.getContentResolver().acquireContentProviderClient(mUri); } else { mProvider = null; } ProviderInfo providerInfo = new ProviderInfo(); providerInfo.authority = uri.getAuthority(); this.attachInfo(mGlobalContext, providerInfo); }
From source file:com.androidclub.source.XmlDocumentProvider.java
/** * Creates an XmlPullParser for the provided local resource. Can be overloaded to provide your * own parser.//from w w w. j a v a 2 s . c o m * @param resourceUri A fully qualified resource name referencing a local XML resource. * @return An XmlPullParser on this resource. */ protected XmlPullParser getResourceXmlPullParser(Uri resourceUri) { //OpenResourceIdResult resourceId; try { String authority = resourceUri.getAuthority(); Resources r; if (TextUtils.isEmpty(authority)) { throw new FileNotFoundException("No authority: " + resourceUri); } else { try { r = getContext().getPackageManager().getResourcesForApplication(authority); } catch (NameNotFoundException ex) { throw new FileNotFoundException("No package found for authority: " + resourceUri); } } List<String> path = resourceUri.getPathSegments(); if (path == null) { throw new FileNotFoundException("No path: " + resourceUri); } int len = path.size(); int id; if (len == 1) { try { id = Integer.parseInt(path.get(0)); } catch (NumberFormatException e) { throw new FileNotFoundException("Single path segment is not a resource ID: " + resourceUri); } } else if (len == 2) { id = r.getIdentifier(path.get(1), path.get(0), authority); } else { throw new FileNotFoundException("More than two path segments: " + resourceUri); } if (id == 0) { throw new FileNotFoundException("No resource found for: " + resourceUri); } return r.getXml(id); } catch (FileNotFoundException e) { Log.w(LOG_TAG, "XML resource not found: " + resourceUri.toString(), e); return null; } }
From source file:com.remobile.file.ContentFilesystem.java
@Override public LocalFilesystemURL toLocalUri(Uri inputURL) { if (!"content".equals(inputURL.getScheme())) { return null; }/* ww w . j av a2 s . c o m*/ String subPath = inputURL.getEncodedPath(); if (subPath.length() > 0) { subPath = subPath.substring(1); } Uri.Builder b = new Uri.Builder().scheme(LocalFilesystemURL.FILESYSTEM_PROTOCOL).authority("localhost") .path(name).appendPath(inputURL.getAuthority()); if (subPath.length() > 0) { b.appendEncodedPath(subPath); } Uri localUri = b.encodedQuery(inputURL.getEncodedQuery()).encodedFragment(inputURL.getEncodedFragment()) .build(); return LocalFilesystemURL.parse(localUri); }
From source file:com.z299studio.pb.ActionDialog.java
private String getFilePath(Activity context, Uri uri) { String docId;//from w w w . j a v a2s.c o m Uri contentUri; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, uri)) { if ("com.android.externalstorage.documents".equals(uri.getAuthority())) { docId = DocumentsContract.getDocumentId(uri); final String split[] = docId.split(":"); if ("primary".equalsIgnoreCase(split[0])) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } } else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) { docId = DocumentsContract.getDocumentId(uri); contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads//public_downloads"), Long.valueOf(docId)); return getDataColumn(context, contentUri, null, null); } } else if (uri.getScheme().equalsIgnoreCase("content")) { return getDataColumn(context, uri, null, null); } else if (uri.getScheme().equalsIgnoreCase("file")) { return uri.getPath(); } return null; }
From source file:com.owncloud.android.lib.test_project.test.OwnCloudClientTest.java
public void testGetWebdavUri() { OwnCloudClient client = new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); client.setCredentials(OwnCloudCredentialsFactory.newBearerCredentials("fakeToken")); Uri webdavUri = client.getWebdavUri(); assertTrue("WebDAV URI does not point to the right entry point for OAuth2 " + "authenticated servers", webdavUri.getPath().endsWith(AccountUtils.ODAV_PATH)); assertTrue("WebDAV URI is not a subpath of base URI", webdavUri.getAuthority().equals(mServerUri.getAuthority()) && webdavUri.getPath().startsWith(mServerUri.getPath())); client.setCredentials(OwnCloudCredentialsFactory.newBasicCredentials(mUsername, mPassword)); webdavUri = client.getWebdavUri();/* w w w . j a va 2s . c o m*/ assertTrue("WebDAV URI does not point to the right entry point", webdavUri.getPath().endsWith(AccountUtils.WEBDAV_PATH_4_0)); PropFindMethod propfind = null; try { propfind = new PropFindMethod(webdavUri + "/", DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_0); int status = client.executeMethod(propfind); assertEquals("WebDAV request did not work on WebDAV URI", HttpStatus.SC_MULTI_STATUS, status); } catch (IOException e) { Log.e(TAG, "Exception in PROPFIND method execution", e); // TODO - make it fail? ; try several times, and make it fail if none // is right? } finally { propfind.releaseConnection(); } }