最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 文件選擇的實(shí)現(xiàn)代碼

 更新時(shí)間:2013年08月19日 15:43:48   作者:  
這篇文章介紹了Android 文件選擇的實(shí)現(xiàn)代碼,有需要的朋友可以參考一下

打開文件選擇器

復(fù)制代碼 代碼如下:

private void showFileChooser() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    try {
        startActivityForResult( Intent.createChooser(intent, "Select a File to Upload"), FILE_SELECT_CODE);
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(this, "Please install a File Manager.",  Toast.LENGTH_SHORT).show();
    }
}

選擇的結(jié)果
復(fù)制代碼 代碼如下:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)  {
    switch (requestCode) {
        case FILE_SELECT_CODE:     
        if (resultCode == RESULT_OK) { 
            // Get the Uri of the selected file
            Uri uri = data.getData();
            String path = FileUtils.getPath(this, uri);
        }          
        break;
    }
super.onActivityResult(requestCode, resultCode, data);
}

FileUtils文件
復(fù)制代碼 代碼如下:

public class FileUtils {
    public static String getPath(Context context, Uri uri) {

        if ("content".equalsIgnoreCase(uri.getScheme())) {
            String[] projection = { "_data" };
            Cursor cursor = null;

            try {
                cursor = context.getContentResolver().query(uri, projection,null, null, null);
                int column_index = cursor.getColumnIndexOrThrow("_data");
                if (cursor.moveToFirst()) {
                    return cursor.getString(column_index);
                }
            } catch (Exception e) {
                // Eat it
            }
        }

        else if ("file".equalsIgnoreCase(uri.getScheme())) {
            return uri.getPath();
        }

        return null;
    }
}

這個(gè)很簡(jiǎn)單。


出處:http://www.cnblogs.com/linlf03/

相關(guān)文章

最新評(píng)論

芮城县| 陇西县| 南宫市| 万源市| 托克逊县| 普安县| 绥德县| 贡嘎县| 岑溪市| 兴国县| 缙云县| 禹州市| 高邑县| 清远市| 天峨县| 屏边| 微山县| 紫云| 沙雅县| 赤峰市| 图们市| 沧州市| 博罗县| 阿拉尔市| 长岛县| 南京市| 什邡市| 康马县| 大竹县| 桓台县| 东乌珠穆沁旗| 舒城县| 漳平市| 万荣县| 策勒县| 西乌珠穆沁旗| 曲周县| 宜兰市| 久治县| 佛教| 河池市|