1

我的代码:

    public class MarkersActivity extends Activity implements MediaScannerConnectionClient{

    public String[] allFiles;
    private String SCAN_PATH ;
    private String PACKAGE_NAME = "testing"
    private static final String FILE_TYPE = "image/*";
    private MediaScannerConnection conn;
    ...
        public void iconPhoto_Click(View v) {
            File directory = new File(Environment.getExternalStorageDirectory() + File.separator + PACKAGE_NAME + File.separator + String.valueOf(selectedID));
            String directory_string = Environment.getExternalStorageDirectory() + File.separator + PACKAGE_NAME + File.separator + String.valueOf(selectedID); 

            if (directory.exists()){
                allFiles = directory.list();
                SCAN_PATH = directory_string + File.separator + allFiles[0];
                startScan();
            }
        }
...
    private void startScan()
    {
        if(conn!=null){
            conn.disconnect();
        }
        conn = new MediaScannerConnection(this, this);
        conn.connect();
    }

    @Override
    public void onMediaScannerConnected()
    {
        conn.scanFile(SCAN_PATH, FILE_TYPE);    
    }

    @Override
    public void onScanCompleted(String path, Uri uri)
    {
        Log.d("!!!!!!!!!!!!!", "onScanCompleted");
        try{
            if (uri != null){
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(uri);
                startActivity(intent);
            }
        }finally{
            conn.disconnect();
            conn = null;
        }
    }   

onScanCompleted - 未运行

Log.d("!!!!!!!!!!!!!", "onScanCompleted"); - 不运行

我希望当您单击按钮时会在我的文件夹的图库中显示照片。在此站点的答案中找到代码,但它不起作用。

我请你告诉我错误在哪里。

请帮助我...谢谢!

4

0 回答 0