链接到SD卡中的文件夹

时间:2013-08-30 10:11:55

标签: java android file hyperlink

您好我想使用简单的图片库,但现在是我的资源文件夹中的源代码。如何将其更改为SD卡中的某个位置?

public class GalleryFileActivity extends Activity {

private GalleryViewPager mViewPager;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    String[] urls = null;
    List<String> items = new ArrayList<String>();
    try {
        urls = getAssets().list("");

        for (String filename : urls) 
        {
            if (filename.matches(".+\\.jpg")) 
            {
                String path = getFilesDir() + "/" + filename;
                copy(getAssets().open(filename), new File(path) );
                items.add(path);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    FilePagerAdapter pagerAdapter = new FilePagerAdapter(this, items);
    pagerAdapter.setOnItemChangeListener(new OnItemChangeListener()
    {
        @Override
        public void onItemChange(int currentPosition)
        {
            Toast.makeText(GalleryFileActivity.this, "Current item is " + currentPosition, Toast.LENGTH_SHORT).show();
        }
    });

    mViewPager = (GalleryViewPager)findViewById(R.id.viewer);
    mViewPager.setOffscreenPageLimit(3);
    mViewPager.setAdapter(pagerAdapter);
}
public void copy(InputStream in, File dst) throws IOException {

    OutputStream out = new FileOutputStream(dst);

    // Transfer bytes from in to out
    byte[] buf = new byte[1024];
    int len;
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    in.close();
    out.close();
}

}

我认为问题出在这一行:“urls = getAssets()。list(”“);”谢谢你的帮助。

0 个答案:

没有答案