List of usage examples for android.content Context getContentResolver
public abstract ContentResolver getContentResolver();
From source file:Main.java
/** * /*from w w w . j a v a 2 s .c om*/ * @param context * @param uri * uri of SCHEME_FILE or SCHEME_CONTENT * @return image path; uri will be changed to SCHEME_FILE */ public static String uriToImagePath(Context context, Uri uri) { if (context == null || uri == null) { return null; } String imagePath = null; String uriString = uri.toString(); String uriSchema = uri.getScheme(); if (uriSchema.equals(ContentResolver.SCHEME_FILE)) { imagePath = uriString.substring("file://".length()); } else {// uriSchema.equals(ContentResolver.SCHEME_CONTENT) ContentResolver resolver = context.getContentResolver(); Cursor cursor = resolver.query(uri, null, null, null, null); if (cursor.getCount() == 0) { Log.e(TAG, "Uri(" + uri.toString() + ") not found!"); return null; } cursor.moveToFirst(); imagePath = cursor.getString(1); // Change the SCHEME_CONTENT uri to the SCHEME_FILE. uri = Uri.fromFile(new File(imagePath)); } Log.v(TAG, "Final uri: " + uri.toString()); return imagePath; }
From source file:com.segment.analytics.internal.Utils.java
/** Creates a unique device id. */ public static String getDeviceId(Context context) { String androidId = getString(context.getContentResolver(), ANDROID_ID); if (!isNullOrEmpty(androidId) && !"9774d56d682e549c".equals(androidId) && !"unknown".equals(androidId) && !"000000000000000".equals(androidId)) { return androidId; }//from w w w .jav a 2s .c om // Serial number, guaranteed to be on all non phones in 2.3+ if (!isNullOrEmpty(Build.SERIAL)) { return Build.SERIAL; } // Telephony ID, guaranteed to be on all phones, requires READ_PHONE_STATE permission if (hasPermission(context, READ_PHONE_STATE) && hasFeature(context, FEATURE_TELEPHONY)) { TelephonyManager telephonyManager = getSystemService(context, TELEPHONY_SERVICE); String telephonyId = telephonyManager.getDeviceId(); if (!isNullOrEmpty(telephonyId)) { return telephonyId; } } // If this still fails, generate random identifier that does not persist across installations return UUID.randomUUID().toString(); }
From source file:air.com.snagfilms.cast.chromecast.utils.Utils.java
public static String getDeviceParameters(Context ctx) { StringBuilder strBlr = null;/*from w w w .j a v a 2 s . c o m*/ String device_id = Secure.getString(ctx.getContentResolver(), Secure.ANDROID_ID); String PhoneModel = android.os.Build.MODEL; strBlr = new StringBuilder(); strBlr.append(Constants.DEVICE_ID); strBlr.append("="); strBlr.append(device_id); strBlr.append("&"); strBlr.append(Constants.DEVICE_MODEL); strBlr.append("="); strBlr.append(PhoneModel); return strBlr.toString(); }
From source file:Main.java
/** Returns a Bitmap from the given URI that may be scaled by an integer factor to reduce its size, * so that its width and height are no greater than the corresponding parameters. The scale factor * will be a power of 2.// ww w.j ava 2 s . c o m */ public static Bitmap scaledBitmapFromURIWithMaximumSize(Context context, Uri imageURI, int width, int height) throws FileNotFoundException { BitmapFactory.Options options = computeBitmapSizeFromURI(context, imageURI); options.inJustDecodeBounds = false; int wratio = powerOf2GreaterOrEqual(1.0 * options.outWidth / width); int hratio = powerOf2GreaterOrEqual(1.0 * options.outHeight / height); options.inSampleSize = Math.max(wratio, hratio); return BitmapFactory.decodeStream(context.getContentResolver().openInputStream(imageURI), null, options); }
From source file:com.browsertophone.DeviceRegistrar.java
private static HttpResponse makeRequest(Context context, String deviceRegistrationID, String urlPath) throws Exception { SharedPreferences settings = Prefs.get(context); String accountName = settings.getString("accountName", null); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("devregid", deviceRegistrationID)); String deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); if (deviceId != null) { params.add(new BasicNameValuePair("deviceId", deviceId)); }//from ww w. ja v a 2 s .c om AppEngineClient client = new AppEngineClient(context, accountName); return client.makeRequest(urlPath, params); }
From source file:Main.java
/** * Returns a fancy search query cursor/* www .j av a2 s . c o m*/ * * @param context * @param query query string * @return cursor of the results */ public static Cursor createSearchQueryCursor(final Context context, final String query) { final Uri uri = Uri.parse("content://media/external/audio/search/fancy/" + Uri.encode(query)); final String[] projection = new String[] { BaseColumns._ID, MediaStore.Audio.Media.MIME_TYPE, MediaStore.Audio.Artists.ARTIST, MediaStore.Audio.Albums.ALBUM, MediaStore.Audio.Media.TITLE, "data1", "data2" }; // no selection/selection/sort args - they are ignored by fancy search anyways return context.getContentResolver().query(uri, projection, null, null, null); }
From source file:Main.java
/** * Get unique device info./* www. j av a 2s . c o m*/ * * @param context application context. * @return returns a json object of the device, manufacturer, build version, and a unique id. */ public static JSONObject getDeviceInfo(Context context) { JSONObject deviceInfo = new JSONObject(); try { deviceInfo.put("device", Build.MODEL); deviceInfo.put("manufacturer", Build.MANUFACTURER); deviceInfo.put("android", android.os.Build.VERSION.SDK); TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String tmDevice = tm.getDeviceId(); String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); String serial = null; if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) serial = Build.SERIAL; if (androidId != null) deviceInfo.put("uid", androidId); else if (serial != null) deviceInfo.put("uid", serial); else if (tmDevice != null) deviceInfo.put("uid", tmDevice); deviceInfo.put("carrier", tm.getNetworkOperatorName()); } catch (JSONException e) { e.printStackTrace(); } return deviceInfo; }
From source file:com.example.android.ennis.barrett.popularmovies.asynchronous.TMDbSyncUtil.java
/** * Gets the ids of any movies marked as favorite * @param context/* w w w. j a v a 2 s .c o m*/ * @return A cursor with the movie ids (from server, not _id) of favorites */ public static Cursor getFavoriteIds(Context context) { return context.getContentResolver().query(TMDbContract.Movies.URI, new String[] { TMDbContract.Movies.MOVIE_ID }, TMDbContract.Movies.IS_FAVORITE + " = ?", new String[] { "1" }, null); }
From source file:mobisocial.musubi.objects.PictureObj.java
public static MemObj from(Context context, Uri imageUri, boolean referenceOrig, String text) throws IOException { // Query gallery for camera picture via // Android ContentResolver interface ContentResolver cr = context.getContentResolver(); UriImage image = new UriImage(context, imageUri); byte[] data = image.getResizedImageData(MAX_IMAGE_WIDTH, MAX_IMAGE_HEIGHT, MAX_IMAGE_SIZE); JSONObject base = new JSONObject(); // Maintain a reference to original file try {/* ww w . ja va 2 s . c o m*/ String type = cr.getType(imageUri); if (type == null) { type = "image/jpeg"; } if (text != null && !text.isEmpty()) { base.put(TEXT, text); } base.put(CorralDownloadClient.OBJ_MIME_TYPE, type); if (referenceOrig) { base.put(CorralDownloadClient.OBJ_LOCAL_URI, imageUri.toString()); String localIp = ContentCorral.getLocalIpAddress(); // TODO: Share IP if allowed for the given feed if (localIp != null && MusubiBaseActivity.isDeveloperModeEnabled(context)) { base.put(DbContactAttributes.ATTR_LAN_IP, localIp); } } } catch (JSONException e) { Log.e(TAG, "impossible json error possible!"); } return new MemObj(TYPE, base, data); }