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


Java CursorLoader.loadInBackground方法代码示例

本文整理汇总了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;
}
 
开发者ID:Justson,项目名称:AgentWeb,代码行数:21,代码来源:AgentWebUtils.java

示例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;
}
 
开发者ID:afiqiqmal,项目名称:MVP-Android,代码行数:21,代码来源:RealPathUtils.java

示例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;
}
 
开发者ID:treasure-lau,项目名称:Linphone4Android,代码行数:13,代码来源:ChatFragment.java

示例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;
}
 
开发者ID:Justson,项目名称:AgentWebX5,代码行数:16,代码来源:AgentWebX5Utils.java

示例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;
}
 
开发者ID:amit-upadhyay-IT,项目名称:contacts-search-android,代码行数:40,代码来源:ContactFetcher.java

示例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();
    }
}
 
开发者ID:Mohnish226,项目名称:SendIt,代码行数:59,代码来源:Video_Activity.java

示例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();
    }
}
 
开发者ID:Mohnish226,项目名称:SendIt,代码行数:59,代码来源:pdf_activity.java

示例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();
        }
    }
 
开发者ID:Mohnish226,项目名称:SendIt,代码行数:61,代码来源:Music_Activity.java

示例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();
    }
}
 
开发者ID:Mohnish226,项目名称:SendIt,代码行数:60,代码来源:Image_Activity.java


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