当前位置: 首页>>代码示例>>Java>>正文


Java Context.getContentResolver方法代码示例

本文整理汇总了Java中android.content.Context.getContentResolver方法的典型用法代码示例。如果您正苦于以下问题:Java Context.getContentResolver方法的具体用法?Java Context.getContentResolver怎么用?Java Context.getContentResolver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.Context的用法示例。


在下文中一共展示了Context.getContentResolver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createPlaylist

import android.content.Context; //导入方法依赖的package包/类
/**
 * @param context The {@link Context} to use.
 * @param name    The name of the new playlist.
 * @return A new playlist ID.
 */
public static final long createPlaylist(final Context context, final String name) {
    if (name != null && name.length() > 0) {
        final ContentResolver resolver = context.getContentResolver();
        final String[] projection = new String[]{
                PlaylistsColumns.NAME
        };
        final String selection = PlaylistsColumns.NAME + " = '" + name + "'";
        Cursor cursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
                projection, selection, null, null);
        if (cursor.getCount() <= 0) {
            final ContentValues values = new ContentValues(1);
            values.put(PlaylistsColumns.NAME, name);
            final Uri uri = resolver.insert(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
                    values);
            return Long.parseLong(uri.getLastPathSegment());
        }
        if (cursor != null) {
            cursor.close();
            cursor = null;
        }
        return -1;
    }
    return -1;
}
 
开发者ID:komamj,项目名称:KomaMusic,代码行数:30,代码来源:MusicUtils.java

示例2: setDataSource

import android.content.Context; //导入方法依赖的package包/类
public void setDataSource(Context context, Uri uri) throws IOException, IllegalArgumentException,
    SecurityException, IllegalStateException {
  if (context == null || uri == null)
    throw new IllegalArgumentException();
  String scheme = uri.getScheme();
  if (scheme == null || scheme.equals("file")) {
    setDataSource(FileUtils.getPath(uri.toString()));
    return;
  }

  try {
    ContentResolver resolver = context.getContentResolver();
    mFD = resolver.openAssetFileDescriptor(uri, "r");
    if (mFD == null)
      return;
    setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor());
    return;
  } catch (Exception e) {
    closeFD();
  }
  Log.e("Couldn't open file on client side, trying server side %s", uri.toString());
  setDataSource(uri.toString());
  return;
}
 
开发者ID:Leavessilent,项目名称:QuanMinTV,代码行数:25,代码来源:MediaMetadataRetriever.java

示例3: getSongFromPath

import android.content.Context; //导入方法依赖的package包/类
public static Song getSongFromPath(String songPath, Context context) {
    ContentResolver cr = context.getContentResolver();

    Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    String selection = MediaStore.Audio.Media.DATA;
    String[] selectionArgs = {songPath};
    String[] projection = new String[]{"_id", "title", "artist", "album", "duration", "track", "artist_id", "album_id"};
    String sortOrder = MediaStore.Audio.Media.TITLE + " ASC";

    Cursor cursor = cr.query(uri, projection, selection + "=?", selectionArgs, sortOrder);

    if (cursor != null && cursor.getCount() > 0) {
        Song song = getSongForCursor(cursor);
        cursor.close();
        return song;
    } else return new Song();
}
 
开发者ID:Vinetos,项目名称:Hello-Music-droid,代码行数:18,代码来源:SongLoader.java

示例4: loadBitmap

import android.content.Context; //导入方法依赖的package包/类
/**
 * Load a bitmap either from a real file or using the {@link ContentResolver} of the current
 * {@link Context} (to read gallery images for example).
 *
 * Note that, when options.inJustDecodeBounds = true, we actually expect sourceImage to remain
 * as null (see https://developer.android.com/training/displaying-bitmaps/load-bitmap.html), so
 * getting null sourceImage at the completion of this method is not always worthy of an error.
 */
private static Bitmap loadBitmap(Context context, String imagePath, BitmapFactory.Options options) throws IOException {
  Bitmap sourceImage = null;
  if (!imagePath.startsWith(CONTENT_PREFIX)) {
    try {
      Log.d(TAG, "loadBitmap: " + imagePath);
      sourceImage = BitmapFactory.decodeFile(imagePath, options);
    } catch (Exception e) {
      e.printStackTrace();
      throw new IOException("Error decoding image file");
    }
  } else {
    ContentResolver cr = context.getContentResolver();
    InputStream input = cr.openInputStream(Uri.parse(imagePath));
    if (input != null) {
      sourceImage = BitmapFactory.decodeStream(input, null, options);
      input.close();
    }
  }
  return sourceImage;
}
 
开发者ID:beast,项目名称:react-native-scan-doc,代码行数:29,代码来源:RNScanDocModule.java

示例5: purgeRecord

import android.content.Context; //导入方法依赖的package包/类
public void purgeRecord(Context context, String fileName)
{
	try
	{
		contentResolver = context.getContentResolver();
		contentUri = DatabaseProvider.TELEPHONE_CALL_CONTENT_URI;
		
       	Cursor cursor = contentResolver.query(contentUri, null, TELEPHONE_CALL.RECORD_FILENAME + " = \"" + fileName + "\" AND LOCKED = 0" ,null, TELEPHONE_CALL.DEFAULT_SORT_ORDER);		        	
		
       	if (cursor.moveToFirst())
       	{
			String recordFolderPath = cursor.getString(cursor.getColumnIndex(TELEPHONE_CALL.RECORD_PATH));
       		String recordFileName = cursor.getString(cursor.getColumnIndex(TELEPHONE_CALL.RECORD_FILENAME));
       		
			purgeRecordFile(context, recordFolderPath, recordFileName);
			
			contentResolver.delete(contentUri,TELEPHONE_CALL.RECORD_FILENAME + " = \"" + recordFileName + "\"",null);
       	}
	}
	catch (Exception e)
	{
		Log.w("PurgeManager", "purgeRecord : " + context.getString(R.string.log_purge_manager_error_purge_record) + " : " + fileName + " : " + e);
		databaseManager.insertLog(context, "" + context.getString(R.string.log_purge_manager_error_purge_record) + " : " + fileName, new Date().getTime(), 2, false);
	}
}
 
开发者ID:vassela,项目名称:AC2RD,代码行数:26,代码来源:PurgeManager.java

示例6: getImgInfo

import android.content.Context; //导入方法依赖的package包/类
/**
 * 获取本地图片信息
 * @param context
 * @param map
 */
public static void getImgInfo(Context context, HashMap<String, ArrayList<String>> map) {
    //获取图片信息表
    Uri imageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
    ContentResolver mContentResolver = context.getContentResolver();
    Cursor mCursor = mContentResolver.query(imageUri, null,
            MediaStore.Images.Media.MIME_TYPE + "=? or " + MediaStore.Images.Media.MIME_TYPE + "=?",
            new String[]{"image/jpeg", "image/png"}, MediaStore.Images.Media.DATE_TAKEN + " DESC");
    while (mCursor.moveToNext()) {
        String imgPath = mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Media.DATA));
        //获取图片父路径
        String parentPath = new File(imgPath).getParentFile().getName();
        if (!map.containsKey(parentPath)) {
            ArrayList<String> childList = new ArrayList<String>();
            childList.add(imgPath);
            map.put(parentPath, childList);
        } else {
            map.get(parentPath).add(imgPath);
        }
    }
    mCursor.close();
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:27,代码来源:MediaUtils.java

示例7: onReceive

import android.content.Context; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    final ContentResolver resolver = context.getContentResolver();

    final String action = intent.getAction();
    if (Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(action)) {
        resolver.call(RecentsProvider.buildRecent(), RecentsProvider.METHOD_PURGE, null, null);

    } else if (Intent.ACTION_PACKAGE_DATA_CLEARED.equals(action)) {
        final Uri data = intent.getData();
        if (data != null) {
            final String packageName = data.getSchemeSpecificPart();
            resolver.call(RecentsProvider.buildRecent(), RecentsProvider.METHOD_PURGE_PACKAGE,
                    packageName, null);
        }
    }
}
 
开发者ID:medalionk,项目名称:simple-share-android,代码行数:18,代码来源:PackageReceiver.java

示例8: countAppsForRepo

import android.content.Context; //导入方法依赖的package包/类
public static int countAppsForRepo(Context context, long repoId) {
    ContentResolver resolver = context.getContentResolver();
    final String[] projection = {Schema.ApkTable.Cols._COUNT_DISTINCT};
    Uri apkUri = ApkProvider.getRepoUri(repoId);
    Cursor cursor = resolver.query(apkUri, projection, null, null, null);
    int count = 0;
    if (cursor != null) {
        if (cursor.getCount() > 0) {
            cursor.moveToFirst();
            count = cursor.getInt(0);
        }
        cursor.close();
    }
    return count;
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:16,代码来源:RepoProvider.java

示例9: getDirItemsNumber

import android.content.Context; //导入方法依赖的package包/类
private static int getDirItemsNumber(Context ctx, Uri u)
{
    int itemsNumber = 0;
    Cursor c = null;
    try
    {
        ContentResolver cr = ctx.getContentResolver();
        String dirId = DocumentsContract.getDocumentId(u);
        Uri dirUri = DocumentsContract.buildChildDocumentsUriUsingTree(u, dirId);
        c = cr.query(dirUri, projection, null, null, null);
        if (c != null)
        {
            itemsNumber = c.getCount();
        }
    }
    catch (Exception e)
    {
        // notning to do;
    }
    finally
    {
        if (c != null)
        {
            c.close();
        }
    }
    return itemsNumber;
}
 
开发者ID:mkulesh,项目名称:microMathematics,代码行数:29,代码来源:AdapterDocuments.java

示例10: hasAccessGranted

import android.content.Context; //导入方法依赖的package包/类
public static boolean hasAccessGranted(Context CONTEXT) {
    ContentResolver contentResolver = CONTEXT.getContentResolver();
    String enabledNotificationListeners = Settings.Secure.getString(contentResolver, "enabled_notification_listeners");
    String packageName = CONTEXT.getPackageName();

    // check to see if the enabledNotificationListeners String contains our package name
    return !(enabledNotificationListeners == null || !enabledNotificationListeners.contains(packageName));
}
 
开发者ID:iboalali,项目名称:sysnotifsnooze,代码行数:9,代码来源:Utils.java

示例11: renamePlaylist

import android.content.Context; //导入方法依赖的package包/类
/**
 * Rename Playlist
 *
 * @param context
 * @param newplaylist
 * @param playlist_id
 */
public static void renamePlaylist(Context context, String newplaylist, long playlist_id) {
    if (permissionManager.writeExternalStorageGranted(context)) {
        Uri newuri = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
        ContentResolver resolver = context.getContentResolver();
        ContentValues values = new ContentValues();
        String where = MediaStore.Audio.Playlists._ID + " =? ";
        String[] whereVal = {Long.toString(playlist_id)};
        values.put(MediaStore.Audio.Playlists.NAME, newplaylist);
        resolver.update(newuri, values, where, whereVal);
    } else {
        Log.e("PlaylistHelper", "Permission failed");
    }
}
 
开发者ID:RajneeshSingh007,项目名称:MusicX-music-player,代码行数:21,代码来源:PlaylistHelper.java

示例12: testLoadResource_withNullFileDescriptor_callsLoadFailed

import android.content.Context; //导入方法依赖的package包/类
@Test
public void testLoadResource_withNullFileDescriptor_callsLoadFailed() {
  Context context = RuntimeEnvironment.application;
  Uri uri = Uri.parse("file://nothing");

  ContentResolver contentResolver = context.getContentResolver();
  ContentResolverShadow shadow = Shadow.extract(contentResolver);
  shadow.registerFileDescriptor(uri, null /*fileDescriptor*/);

  FileDescriptorLocalUriFetcher fetcher =
      new FileDescriptorLocalUriFetcher(context.getContentResolver(), uri);
  fetcher.loadData(Priority.NORMAL, callback);
  verify(callback).onLoadFailed(isA(FileNotFoundException.class));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:FileDescriptorLocalUriFetcherTest.java

示例13: updateItemsInDatabaseHelper

import android.content.Context; //导入方法依赖的package包/类
static void updateItemsInDatabaseHelper(Context context, final ArrayList<ContentValues> valuesList,
        final ArrayList<ItemInfo> items, final String callingFunction) {
    final ContentResolver cr = context.getContentResolver();

    final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
    Runnable r = new Runnable() {
        public void run() {
            ArrayList<ContentProviderOperation> ops =
                    new ArrayList<ContentProviderOperation>();
            int count = items.size();
            for (int i = 0; i < count; i++) {
                ItemInfo item = items.get(i);
                final long itemId = item.id;
                final Uri uri = LauncherSettings.Favorites.getContentUri(itemId);
                ContentValues values = valuesList.get(i);

                ops.add(ContentProviderOperation.newUpdate(uri).withValues(values).build());
                updateItemArrays(item, itemId, stackTrace);

            }
            try {
                cr.applyBatch(LauncherProvider.AUTHORITY, ops);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    runOnWorkerThread(r);
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:30,代码来源:LauncherModel.java

示例14: deleteItemsFromDatabase

import android.content.Context; //导入方法依赖的package包/类
/**
 * Removes the specified items from the database
 */
static void deleteItemsFromDatabase(Context context, final ArrayList<? extends ItemInfo> items) {
    final ContentResolver cr = context.getContentResolver();
    Runnable r = new Runnable() {
        public void run() {
            for (ItemInfo item : items) {
                final Uri uri = LauncherSettings.Favorites.getContentUri(item.id);
                cr.delete(uri, null, null);

                // Lock on mBgLock *after* the db operation
                synchronized (sBgLock) {
                    switch (item.itemType) {
                        case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
                            sBgFolders.remove(item.id);
                            for (ItemInfo info: sBgItemsIdMap) {
                                if (info.container == item.id) {
                                    // We are deleting a folder which still contains items that
                                    // think they are contained by that folder.
                                    String msg = "deleting a folder (" + item + ") which still " +
                                            "contains items (" + info + ")";
                                    Log.e(TAG, msg);
                                }
                            }
                            sBgWorkspaceItems.remove(item);
                            break;
                        case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
                            decrementPinnedShortcutCount(ShortcutKey.fromShortcutInfo(
                                    (ShortcutInfo) item));
                            // Fall through.
                        case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
                        case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
                            sBgWorkspaceItems.remove(item);
                            break;
                        case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
                            sBgAppWidgets.remove((LauncherAppWidgetInfo) item);
                            break;
                    }
                    sBgItemsIdMap.remove(item.id);
                }
            }
        }
    };
    runOnWorkerThread(r);
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:47,代码来源:LauncherModel.java

示例15: get

import android.content.Context; //导入方法依赖的package包/类
/**
 * Find by the content URI of a repo ({@link RepoProvider#getContentUri(long)}).
 */
public static Repo get(Context context, Uri uri) {
    ContentResolver resolver = context.getContentResolver();
    Cursor cursor = resolver.query(uri, Cols.ALL, null, null, null);
    return cursorToRepo(cursor);
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:9,代码来源:RepoProvider.java


注:本文中的android.content.Context.getContentResolver方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。