本文整理汇总了Java中android.support.v4.content.CursorLoader.loadInBackground方法的典型用法代码示例。如果您正苦于以下问题:Java CursorLoader.loadInBackground方法的具体用法?Java CursorLoader.loadInBackground怎么用?Java CursorLoader.loadInBackground使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.content.CursorLoader
的用法示例。
在下文中一共展示了CursorLoader.loadInBackground方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRealPathBelowVersion
import android.support.v4.content.CursorLoader; //导入方法依赖的package包/类
private static String getRealPathBelowVersion(Context context, Uri uri) {
String filePath = null;
LogUtils.i(TAG, "method -> getRealPathBelowVersion " + uri + " path:" + uri.getPath() + " getAuthority:" + uri.getAuthority());
String[] projection = {MediaStore.Images.Media.DATA};
CursorLoader loader = new CursorLoader(context, uri, projection, null,
null, null);
Cursor cursor = loader.loadInBackground();
if (cursor != null) {
cursor.moveToFirst();
filePath = cursor.getString(cursor.getColumnIndex(projection[0]));
cursor.close();
}
if (filePath == null) {
filePath = uri.getPath();
}
return filePath;
}
示例2: getRealPathFromURI_API11to18
import android.support.v4.content.CursorLoader; //导入方法依赖的package包/类
@SuppressLint("NewApi")
public static String getRealPathFromURI_API11to18(Context context, Uri contentUri) {
String[] proj = { MediaStore.Images.Media.DATA };
String result = null;
try {
CursorLoader cursorLoader = new CursorLoader(context, contentUri, proj, null, null, null);
Cursor cursor = cursorLoader.loadInBackground();
if (cursor != null) {
int column_index =
cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
result = cursor.getString(column_index);
}
}
catch (Exception e){
e.printStackTrace();
}
return result;
}
示例3: getRealPathFromURI
import android.support.v4.content.CursorLoader; //导入方法依赖的package包/类
public String getRealPathFromURI(Uri contentUri) {
String[] proj = {MediaStore.Images.Media.DATA};
CursorLoader loader = new CursorLoader(getActivity(), contentUri, proj, null, null, null);
Cursor cursor = loader.loadInBackground();
if (cursor != null && cursor.moveToFirst()) {
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
String result = cursor.getString(column_index);
cursor.close();
return result;
}
return null;
}
示例4: getRealPathBelowVersion
import android.support.v4.content.CursorLoader; //导入方法依赖的package包/类
private static String getRealPathBelowVersion(Context context, Uri uri) {
String filePath = null;
String[] projection = {MediaStore.Images.Media.DATA};
CursorLoader loader = new CursorLoader(context, uri, projection, null,
null, null);
Cursor cursor = loader.loadInBackground();
if (cursor != null) {
cursor.moveToFirst();
filePath = cursor.getString(cursor.getColumnIndex(projection[0]));
cursor.close();
}
return filePath;
}
示例5: fetchAll
import android.support.v4.content.CursorLoader; //导入方法依赖的package包/类
public ArrayList<Contact> fetchAll() {
String[] projectionFields = new String[]{
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME,
};
ArrayList<Contact> listContacts = new ArrayList<>();
CursorLoader cursorLoader = new CursorLoader(context,
ContactsContract.Contacts.CONTENT_URI,
projectionFields, // the columns to retrieve
null, // the selection criteria (none)
null, // the selection args (none)
Phone.DISPLAY_NAME + " ASC" // the sort order (default), use null for default
);
Cursor c = cursorLoader.loadInBackground();
final Map<String, Contact> contactsMap = new HashMap<>(c.getCount());
if (c.moveToFirst()) {
int idIndex = c.getColumnIndex(ContactsContract.Contacts._ID);
int nameIndex = c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
do {
String contactId = c.getString(idIndex);
String contactDisplayName = c.getString(nameIndex);
Contact contact = new Contact(contactId, contactDisplayName);
contactsMap.put(contactId, contact);
listContacts.add(contact);
} while (c.moveToNext());
}
c.close();
matchContactNumbers(contactsMap);
matchContactEmails(contactsMap);
return listContacts;
}
示例6: onCreate
import android.support.v4.content.CursorLoader; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
try {
ListView lv = (ListView) findViewById(R.id.videolist);
String[] projection = {
MediaStore.Files.FileColumns.TITLE,
MediaStore.Files.FileColumns.DATA
};
// Return only video metadata.
String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
+ MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO;
Uri queryUri = MediaStore.Files.getContentUri("external");
CursorLoader cursorLoader = new CursorLoader(
this,
queryUri,
projection,
selection,
null, // Selection args (none).
MediaStore.Files.FileColumns.DISPLAY_NAME // Sort order.
);
Cursor cursor = cursorLoader.loadInBackground();
final List<String> file_list = new ArrayList<>();
final List<String> file_data=new ArrayList<>();
if (cursor.moveToFirst()) {
do {
file_list.add(cursor.getString(cursor.getColumnIndex(projection[0])));
file_data.add(cursor.getString(cursor.getColumnIndex(projection[1])));
}while (cursor.moveToNext());
}
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>
(this, android.R.layout.simple_list_item_1, file_list);
lv.setAdapter(arrayAdapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
String strName = file_data.get(arg2);
//Toast.makeText(getApplicationContext(), " " + strName, Toast.LENGTH_LONG).show();
Intent i = new Intent(Video_Activity.this, sendActivity.class);
i.putExtra("Data", strName);
startActivity(i);
}
});
}catch (Exception e){
Toast.makeText(getApplicationContext(),e.toString(),Toast.LENGTH_LONG).show();
}
}
示例7: onCreate
import android.support.v4.content.CursorLoader; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_apk);
ListView lv=(ListView)findViewById(R.id.apklist);
try {
String[] projection = {
MediaStore.Files.FileColumns.TITLE,
MediaStore.Files.FileColumns.DATA
};
String selection = MediaStore.Files.FileColumns.MIME_TYPE + "=?";
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension("pdf");
String[] selectionArgsAPK = new String[]{ mimeType };
Uri queryUri = MediaStore.Files.getContentUri("external");
CursorLoader cursorLoader = new CursorLoader(
this,
queryUri,
projection,
selection,
selectionArgsAPK, // Selection args pdf
MediaStore.Files.FileColumns.DISPLAY_NAME // Sort order.
);
Cursor cursor = cursorLoader.loadInBackground();
final List<String> file_list = new ArrayList<>();
final List<String> file_data = new ArrayList<>();
if (cursor.moveToFirst()) {
do {
file_list.add(cursor.getString(cursor.getColumnIndex(projection[0])));
file_data.add(cursor.getString(cursor.getColumnIndex(projection[1])));
} while (cursor.moveToNext());
}
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>
(this, android.R.layout.simple_list_item_1, file_list);
lv.setAdapter(arrayAdapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
String strName = file_data.get(arg2);
//Toast.makeText(getApplicationContext(), " " + strName, Toast.LENGTH_LONG).show();
Intent i = new Intent(pdf_activity.this, sendActivity.class);
i.putExtra("Data", strName);
startActivity(i);
}
});
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
}
}
示例8: onCreate
import android.support.v4.content.CursorLoader; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_music_);
try {
ListView lv = (ListView) findViewById(R.id.audiolist);
String[] projection = {
MediaStore.Files.FileColumns.TITLE,
MediaStore.Files.FileColumns.DATA
};
// Return only video and image metadata.
String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
+ MediaStore.Files.FileColumns.MEDIA_TYPE_AUDIO;
Uri queryUri = MediaStore.Files.getContentUri("external");
CursorLoader cursorLoader = new CursorLoader(
this,
queryUri,
projection,
selection,
null, // Selection args (none).
MediaStore.Files.FileColumns.DISPLAY_NAME// Sort order.
);
Cursor cursor = cursorLoader.loadInBackground();
final List<String> file_list = new ArrayList<>();
final List<String> file_data=new ArrayList<>();
if (cursor.moveToFirst()) {
do {
file_list.add(cursor.getString(cursor.getColumnIndex(projection[0])));
file_data.add(cursor.getString(cursor.getColumnIndex(projection[1])));
}while (cursor.moveToNext());
}
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>
(this, android.R.layout.simple_list_item_1, file_list);
lv.setAdapter(arrayAdapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
String strName = file_data.get(arg2);
//Toast.makeText(getApplicationContext(), " " + strName, Toast.LENGTH_LONG).show();
Intent i = new Intent(Music_Activity.this, sendActivity.class);
i.putExtra("Data", strName);
startActivity(i);
}
});
}catch (Exception e){
Toast.makeText(getApplicationContext(),e.toString(),Toast.LENGTH_LONG).show();
}
}
示例9: onCreate
import android.support.v4.content.CursorLoader; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image);
try {
ListView lv = (ListView) findViewById(R.id.imagelist);
String[] projection = {
MediaStore.Files.FileColumns.TITLE,
MediaStore.Files.FileColumns.DATA
};
// Return only image metadata.
String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
+ MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE;
Uri queryUri = MediaStore.Files.getContentUri("external");
CursorLoader cursorLoader = new CursorLoader(
this,
queryUri,
projection,
selection,
null, // Selection args (none).
MediaStore.Files.FileColumns.DISPLAY_NAME // Sort order.
);
Cursor cursor = cursorLoader.loadInBackground();
final List<String> file_list = new ArrayList<>();
final List<String> file_data = new ArrayList<>();
if (cursor.moveToFirst()) {
do {
file_list.add(cursor.getString(cursor.getColumnIndex(projection[0])));
file_data.add(cursor.getString(cursor.getColumnIndex(projection[1])));
}while (cursor.moveToNext());
}
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>
(this, android.R.layout.simple_list_item_1, file_list);
lv.setAdapter(arrayAdapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
String strName = file_data.get(arg2);
//Toast.makeText(getApplicationContext(), " " + strName, Toast.LENGTH_LONG).show();
Intent i = new Intent(Image_Activity.this, sendActivity.class);
i.putExtra("Data", strName);
startActivity(i);
}
});
}catch (Exception e){
Toast.makeText(getApplicationContext(),e.toString(),Toast.LENGTH_LONG).show();
}
}