-1

我想在我的应用程序中有一个按钮,当按下该按钮时,用户将被带到手机内置的图库应用程序。如果可能的话,我希望用户被带到应用程序创建的目录。有没有办法在Android中做到这一点?如果应用程序在他们进入画廊后结束,那也没关系。

4

2 回答 2

0

您可以使用意图在 android 中使用 defalut Gallery,这里的代码是-

Button GalleryButton=(Button)this.findViewById(R.id.galleryview); GalleryButton.setOnClickListener(new OnClickListener() {

    public void onClick(View arg0) {

        // in onCreate or any event where your want the user to
        // select a file
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent,
                "Select Picture"), SELECT_PICTURE);
    }
});

}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            if (requestCode == SELECT_PICTURE) {
                Uri selectedImageUri = data.getData();
                filemanagerstring = selectedImageUri.getPath();
                selectedImagePath = getPath(selectedImageUri);

                if(selectedImagePath!=null)
                    System.out.println(selectedImagePath);
                else System.out.println("selectedImagePath is null");
                if(filemanagerstring!=null)
                    System.out.println(filemanagerstring);
                else System.out.println("filemanagerstring is null");

                if(selectedImagePath!=null)
                    System.out.println("selectedImagePath is the right one for you!");
                else
                    System.out.println("filemanagerstring is the right one for you!");
            }
        }
    }

    public String getPath(Uri uri) {
        String[] projection = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(uri, projection, null, null, null);
        if(cursor!=null)
        {
            int column_index = cursor
            .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        }
        else return null;
    }
于 2013-07-26T05:15:18.503 回答
0

试试这个代码......!

按钮 btn = (按钮) findViewById(R.id.btn);

btn.setOnClickListener(new OnClickListener()
{
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Picture"), 0);

    }
}); 
于 2013-07-26T04:54:08.080 回答