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


Java ContentResolver.query方法代码示例

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


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

示例1: queryForLong

import android.content.ContentResolver; //导入方法依赖的package包/类
private static long queryForLong(Context context, Uri self, String column,
        long defaultValue) {
    final ContentResolver resolver = context.getContentResolver();

    Cursor c = null;
    try {
        c = resolver.query(self, new String[] { column }, null, null, null);
        if (c.moveToFirst() && !c.isNull(0)) {
            return c.getLong(0);
        } else {
            return defaultValue;
        }
    } catch (Exception e) {
        Log.w(TAG, "Failed query: " + e);
        return defaultValue;
    } finally {
        closeQuietly(c);
    }
}
 
开发者ID:gigabytedevelopers,项目名称:FireFiles,代码行数:20,代码来源:DocumentsContractApi19.java

示例2: onClick

import android.content.ContentResolver; //导入方法依赖的package包/类
public void onClick( View v ) 
{
	ContentResolver contentResolver = getContentResolver();
	Cursor cursor = contentResolver.query( Uri.parse( "content://sms/inbox" ), null, null, null, null);

	int indexBody = cursor.getColumnIndex( SmsReceiver.BODY );
	int indexAddr = cursor.getColumnIndex( SmsReceiver.ADDRESS );
	
	if ( indexBody < 0 || !cursor.moveToFirst() ) return;
	
	smsList.clear();
	
	do
	{
		String str = "Sender: " + cursor.getString( indexAddr ) + "\n" + cursor.getString( indexBody );
		smsList.add( str );
	}
	while( cursor.moveToNext() );

	
	ListView smsListView = (ListView) findViewById( R.id.SMSList );
	smsListView.setAdapter( new ArrayAdapter<String>( this, android.R.layout.simple_list_item_1, smsList) );
	smsListView.setOnItemClickListener( this );
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:25,代码来源:SecureMessagesActivity.java

示例3: loadArtistList

import android.content.ContentResolver; //导入方法依赖的package包/类
public static ArrayList<Artist> loadArtistList(ContentResolver resolver) {
        ArrayList<Artist> list = new ArrayList<>();
        Cursor cursor = resolver.query(
                MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI,
                new String[]{
                        MediaStore.Audio.Artists._ID,
                        MediaStore.Audio.Artists.ARTIST,
//                        MediaStore.Audio.Artists.
                },
                null, null, MediaStore.Audio.Artists.ARTIST);
        if (cursor != null) {
            if (cursor.moveToFirst()) {
                do {
                    Artist artist = new Artist();
                    artist.setId(cursor.getInt(0));
                    artist.setName(cursor.getString(1));
                    list.add(artist);
                } while (cursor.moveToNext());
            }
            cursor.close();
        }
        return list;
    }
 
开发者ID:Jaysaw,项目名称:NovaMusicPlayer,代码行数:24,代码来源:MediaStoreHelper.java

示例4: getFileFromMediaUri

import android.content.ContentResolver; //导入方法依赖的package包/类
/**
 * 通过Uri获取文件
 *
 * @param ac
 * @param uri
 * @return
 */
public static File getFileFromMediaUri(Context ac, Uri uri) {
    if (uri.getScheme().toString().compareTo("content") == 0) {
        ContentResolver cr = ac.getContentResolver();
        Cursor cursor = cr.query(uri, null, null, null, null);// 根据Uri从数据库中找
        if (cursor != null) {
            cursor.moveToFirst();
            String filePath = cursor.getString(cursor.getColumnIndex("_data"));// 获取图片路径
            cursor.close();
            if (filePath != null) {
                return new File(filePath);
            }
        }
    } else if (uri.getScheme().toString().compareTo("file") == 0) {
        return new File(uri.toString().replace("file://", ""));
    }
    return null;
}
 
开发者ID:StickyTolt,项目名称:ForeverLibrary,代码行数:25,代码来源:PictureUtil.java

示例5: getPath

import android.content.ContentResolver; //导入方法依赖的package包/类
public static String getPath(ContentResolver resolver, Uri uri) {
    if (uri == null) {
        return null;
    }

    if (SCHEME_CONTENT.equals(uri.getScheme())) {
        Cursor cursor = null;
        try {
            cursor = resolver.query(uri, new String[]{MediaStore.Images.ImageColumns.DATA},
                    null, null, null);
            if (cursor == null || !cursor.moveToFirst()) {
                return null;
            }
            return cursor.getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA));
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }
    return uri.getPath();
}
 
开发者ID:GitPhoenix,项目名称:VanGogh,代码行数:23,代码来源:PhotoMetadataUtils.java

示例6: getALlPlalists

import android.content.ContentResolver; //导入方法依赖的package包/类
public static ArrayList<String[]> getALlPlalists(ContentResolver Cr){
    ArrayList<String[]> list = new ArrayList<String[]>();
    Uri uri = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
    String[] cols = new String[] {MediaStore.Audio.Playlists.NAME, MediaStore.Audio.Playlists._ID};
    Cursor DataCursor =  Cr.query( uri,cols, null,null, MediaStore.Audio.Playlists.NAME +" COLLATE NOCASE ASC");// +" COLLATE NOCASE ASC");

    int length = DataCursor.getCount();
    for (int i = 0; i < length; i++) {
        DataCursor.moveToNext();
        String str = DataCursor.getString(0);
        if(!str.startsWith(" ") && str.length() != 0){
            list.add(new String[] {str,DataCursor.getInt(1)+""});
        }
    }
    DataCursor.close();
    return list;
}
 
开发者ID:KishanV,项目名称:Android-Music-Player,代码行数:18,代码来源:playlistHandler.java

示例7: enabledAlarms

import android.content.ContentResolver; //导入方法依赖的package包/类
private List<Alarm> enabledAlarms(ContentResolver r) {
  LinkedList<Alarm> ids = new LinkedList<Alarm>();
  Cursor c = r.query(
      AlarmClockProvider.ALARMS_URI,
      new String[] {
        AlarmClockProvider.AlarmEntry._ID,
        AlarmClockProvider.AlarmEntry.TIME,
        AlarmClockProvider.AlarmEntry.DAY_OF_WEEK,
        AlarmClockProvider.AlarmEntry.NEXT_SNOOZE },
      AlarmClockProvider.AlarmEntry.ENABLED + " == 1",
      null, null);
  while (c.moveToNext())
    ids.add(new Alarm(c));
  c.close();
  return ids;
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:17,代码来源:SystemMessageReceiver.java

示例8: makeArtistSongCursor

import android.content.ContentResolver; //导入方法依赖的package包/类
public static Cursor makeArtistSongCursor(Context context, long artistID) {
    ContentResolver contentResolver = context.getContentResolver();
    final String artistSongSortOrder = PreferencesUtility.getInstance(context).getArtistSongSortOrder();
    Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    String string = "is_music=1 AND title != '' AND artist_id=" + artistID;
    return contentResolver.query(uri, new String[]{"_id", "title", "artist", "album", "duration", "track", "album_id"}, string, null, artistSongSortOrder);
}
 
开发者ID:Vinetos,项目名称:Hello-Music-droid,代码行数:8,代码来源:ArtistSongLoader.java

示例9: getMaxId

import android.content.ContentResolver; //导入方法依赖的package包/类
/** helper to find the max of _id (=newest in android's db) in our db */
private static String getMaxId (ContentResolver cr) {
    Cursor c = cr.query(MusicStoreInternal.FILES_IMPORT, MAX_ID_PROJ, null, null, null);
    String result = null;
    if (c != null) {
        if (c.moveToFirst()) {
            result = c.getString(0);
        }
        c.close();
    }
    return TextUtils.isEmpty(result) ? "0" : result;
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:13,代码来源:MusicStoreImportImpl.java

示例10: getFromMediaUri

import android.content.ContentResolver; //导入方法依赖的package包/类
@Nullable
public static File getFromMediaUri(Context context, ContentResolver resolver, Uri uri) {
    if (uri == null) return null;

    if (SCHEME_FILE.equals(uri.getScheme())) {
        return new File(uri.getPath());
    } else if (SCHEME_CONTENT.equals(uri.getScheme())) {
        final String[] filePathColumn = { MediaStore.MediaColumns.DATA, MediaStore.MediaColumns.DISPLAY_NAME };
        Cursor cursor = null;
        try {
            cursor = resolver.query(uri, filePathColumn, null, null, null);
            if (cursor != null && cursor.moveToFirst()) {
                final int columnIndex = (uri.toString().startsWith("content://com.google.android.gallery3d")) ?
                        cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME) :
                        cursor.getColumnIndex(MediaStore.MediaColumns.DATA);
                // Picasa images on API 13+
                if (columnIndex != -1) {
                    String filePath = cursor.getString(columnIndex);
                    if (!TextUtils.isEmpty(filePath)) {
                        return new File(filePath);
                    }
                }
            }
        } catch (IllegalArgumentException e) {
            // Google Drive images
            return getFromMediaUriPfd(context, resolver, uri);
        } catch (SecurityException ignored) {
            // Nothing we can do
        } finally {
            if (cursor != null) cursor.close();
        }
    }
    return null;
}
 
开发者ID:liuyanggithub,项目名称:SuperSelector,代码行数:35,代码来源:CropUtil.java

示例11: query

import android.content.ContentResolver; //导入方法依赖的package包/类
private static Cursor query(Context context, Uri uri, String[] projection,
		String selection, String[] selectionArgs, String sortOrder) {
	try {
		ContentResolver resolver = context.getContentResolver();
		if (resolver == null) {
			return null;
		}
		return resolver.query(uri, projection, selection, selectionArgs, sortOrder);
	} catch (UnsupportedOperationException ex) {
		return null;
	}
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:13,代码来源:LibraryUtils.java

示例12: exists

import android.content.ContentResolver; //导入方法依赖的package包/类
public static boolean exists(Context context, Uri self) {
    final ContentResolver resolver = context.getContentResolver();

    Cursor c = null;
    try {
        c = resolver.query(self, new String[] {
                DocumentsContract.Document.COLUMN_DOCUMENT_ID }, null, null, null);
        return c.getCount() > 0;
    } catch (Exception e) {
        Log.w(TAG, "Failed query: " + e);
        return false;
    } finally {
        closeQuietly(c);
    }
}
 
开发者ID:gigabytedevelopers,项目名称:FireFiles,代码行数:16,代码来源:DocumentsContractApi19.java

示例13: getMaxLocalId

import android.content.ContentResolver; //导入方法依赖的package包/类
private static String getMaxLocalId (ContentResolver cr) {
    Cursor c = cr.query(MusicStoreInternal.FILES_IMPORT, MAX_LOCAL_PROJ, null, null, null);
    String result = null;
    if (c != null) {
        if (c.moveToFirst()) {
            result = c.getString(0);
        }
        c.close();
    }
    return TextUtils.isEmpty(result) ? "0" : result;
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:12,代码来源:MusicStoreImportImpl.java

示例14: checkWriteContacts

import android.content.ContentResolver; //导入方法依赖的package包/类
/**
 * write and delete contacts info, {@link Manifest.permission#WRITE_CONTACTS}
 * and we should get read contacts permission first.
 *
 * @param activity
 * @return true if success
 * @throws Exception
 */
private static boolean checkWriteContacts(Context activity) throws Exception {
    if (checkReadContacts(activity)) {
        // write some info
        ContentValues values = new ContentValues();
        ContentResolver contentResolver = activity.getContentResolver();
        Uri rawContactUri = contentResolver.insert(ContactsContract.RawContacts
                .CONTENT_URI, values);
        long rawContactId = ContentUris.parseId(rawContactUri);
        values.put(ContactsContract.Contacts.Data.MIMETYPE, ContactsContract.CommonDataKinds
                .StructuredName.CONTENT_ITEM_TYPE);
        values.put(ContactsContract.Contacts.Data.RAW_CONTACT_ID, rawContactId);
        values.put(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, TAG);
        values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, TAG_NUMBER);
        contentResolver.insert(ContactsContract.Data.CONTENT_URI, values);

        // delete info
        Uri uri = Uri.parse("content://com.android.contacts/raw_contacts");
        ContentResolver resolver = activity.getContentResolver();
        Cursor cursor = resolver.query(uri, new String[]{ContactsContract.Contacts.Data._ID},
                "display_name=?", new String[]{TAG}, null);
        if (cursor != null) {
            if (cursor.moveToFirst()) {
                int id = cursor.getInt(0);
                resolver.delete(uri, "display_name=?", new String[]{TAG});
                uri = Uri.parse("content://com.android.contacts/data");
                resolver.delete(uri, "raw_contact_id=?", new String[]{id + ""});
            }
            cursor.close();
        }
        return true;
    } else {
        return false;
    }
}
 
开发者ID:paozhuanyinyu,项目名称:XPermission,代码行数:43,代码来源:PermissionsChecker.java

示例15: testCanUpdate

import android.content.ContentResolver; //导入方法依赖的package包/类
@Test
public void testCanUpdate() {
    insertApp("not installed", "not installed");
    insertAndInstallApp("installed, only one version available", 1, 1, false, 0);
    insertAndInstallApp("installed, already latest, no ignore", 10, 10, false, 0);
    insertAndInstallApp("installed, already latest, ignore all", 10, 10, true, 0);
    insertAndInstallApp("installed, already latest, ignore latest", 10, 10, false, 10);
    insertAndInstallApp("installed, already latest, ignore old", 10, 10, false, 5);
    insertAndInstallApp("installed, old version, no ignore", 5, 10, false, 0);
    insertAndInstallApp("installed, old version, ignore all", 5, 10, true, 0);
    insertAndInstallApp("installed, old version, ignore latest", 5, 10, false, 10);
    insertAndInstallApp("installed, old version, ignore newer, but not latest", 5, 10, false, 8);

    ContentResolver r = context.getContentResolver();

    // Can't "update", although can "install"...
    App notInstalled = AppProvider.Helper.findSpecificApp(r, "not installed", 1, Cols.ALL);
    assertFalse(notInstalled.canAndWantToUpdate(context));

    assertResultCount(contentResolver, 2, AppProvider.getCanUpdateUri(), PROJ);
    assertResultCount(contentResolver, 9, AppProvider.getInstalledUri(), PROJ);

    App installedOnlyOneVersionAvailable = AppProvider.Helper.findSpecificApp(r, "installed, only one version available", 1, Cols.ALL);
    App installedAlreadyLatestNoIgnore = AppProvider.Helper.findSpecificApp(r, "installed, already latest, no ignore", 1, Cols.ALL);
    App installedAlreadyLatestIgnoreAll = AppProvider.Helper.findSpecificApp(r, "installed, already latest, ignore all", 1, Cols.ALL);
    App installedAlreadyLatestIgnoreLatest = AppProvider.Helper.findSpecificApp(r, "installed, already latest, ignore latest", 1, Cols.ALL);
    App installedAlreadyLatestIgnoreOld = AppProvider.Helper.findSpecificApp(r, "installed, already latest, ignore old", 1, Cols.ALL);

    assertFalse(installedOnlyOneVersionAvailable.canAndWantToUpdate(context));
    assertFalse(installedAlreadyLatestNoIgnore.canAndWantToUpdate(context));
    assertFalse(installedAlreadyLatestIgnoreAll.canAndWantToUpdate(context));
    assertFalse(installedAlreadyLatestIgnoreLatest.canAndWantToUpdate(context));
    assertFalse(installedAlreadyLatestIgnoreOld.canAndWantToUpdate(context));

    App installedOldNoIgnore = AppProvider.Helper.findSpecificApp(r, "installed, old version, no ignore", 1, Cols.ALL);
    App installedOldIgnoreAll = AppProvider.Helper.findSpecificApp(r, "installed, old version, ignore all", 1, Cols.ALL);
    App installedOldIgnoreLatest = AppProvider.Helper.findSpecificApp(r, "installed, old version, ignore latest", 1, Cols.ALL);
    App installedOldIgnoreNewerNotLatest = AppProvider.Helper.findSpecificApp(r, "installed, old version, ignore newer, but not latest", 1, Cols.ALL);

    assertTrue(installedOldNoIgnore.canAndWantToUpdate(context));
    assertFalse(installedOldIgnoreAll.canAndWantToUpdate(context));
    assertFalse(installedOldIgnoreLatest.canAndWantToUpdate(context));
    assertTrue(installedOldIgnoreNewerNotLatest.canAndWantToUpdate(context));

    Cursor canUpdateCursor = r.query(AppProvider.getCanUpdateUri(), Cols.ALL, null, null, null);
    assertNotNull(canUpdateCursor);
    canUpdateCursor.moveToFirst();
    List<String> canUpdateIds = new ArrayList<>(canUpdateCursor.getCount());
    while (!canUpdateCursor.isAfterLast()) {
        canUpdateIds.add(new App(canUpdateCursor).packageName);
        canUpdateCursor.moveToNext();
    }
    canUpdateCursor.close();

    String[] expectedUpdateableIds = {
            "installed, old version, no ignore",
            "installed, old version, ignore newer, but not latest",
    };

    assertContainsOnly(expectedUpdateableIds, canUpdateIds);
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:62,代码来源:AppProviderTest.java


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