4

Possible Duplicate:
Gallery with folder filter

I'm using following code to open a gallery inside of my app

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, TEST_RESULT);

I need to use the buil-in gallery app to SHOW a list of images/videos in a specific folder. - There is some Intent action to SHOW the selected image when the gallery is opened??? - Is there any way to determine a specific folder of images?**I want the gallery to show only the images/videos in my folder (and no other system folders).

Community
  • 1
  • 1
guilherme.minglini
  • 564
  • 2
  • 6
  • 20
  • Complete solution already discussed here - http://stackoverflow.com/questions/2169649/open-an-image-in-androids-built-in-gallery-app-programmatically/2636538#2636538 – peter_budo May 20 '11 at 15:45
  • 2
    @peter_budo: First please see the difference between two questions, i searched a lot and this question is valid coz the url that u suggested above is not the answer that what he asked... – PiyushMishra Nov 20 '11 at 13:19
  • @peter_budo No one is a mind reader in the world, I am trying to raise the things that some moderator try to close the question as soon as possible just pass them a link even though the answer didnt relate to the question, so its my humble request to all the moderator first please see the question with user point of view, What he/she want to ask. I am not saying that u done something wrong by passing the link but the link not much related to what user asked.. – PiyushMishra Nov 22 '11 at 07:19
  • @PiyushMishra I'm not moderator just wonder where you came up with that nonsense. Secondly linked solution is workable approach. What you need to do is take that code and adjust it little. Do not expect people to give you "full code on golden plate" – peter_budo Nov 22 '11 at 18:01
  • @peter_budo i am not at all in favor of providing full code on golden plate. And i think first you need to learn how to speak well, you might a good programmer but you need to learn few things. I am ending this conversation no need to discuss further more. Have a nice day – PiyushMishra Nov 23 '11 at 06:58
  • 3
    @peter_budo: The link that you provided, do you test any of code no one tell how to open a exact folder inside built in gallery except anthony who tried to do that but that code again wont work you can see that in comment of the user and time is equally important for both of us i think. – PiyushMishra Nov 23 '11 at 07:27
  • @peter_budo I gotta agree with PiyushMishra. The question you referred didn't help me much. BTW, I was not looking for complete code but reference or hint. – Tae-Sung Shin Nov 24 '11 at 14:40
  • @peter_budo The linked question is NOT a duplicate of this question and is no way near of a solution to this question. The duplicate state should be removed. Valid answer to this specific question has been given here and have nothing related to the linked question. – qwertzguy Jul 01 '13 at 18:21
  • @qwertzguy you just one and half year let. Well done on bumping old duplicate. "marked as duplicate by Brock Adams, Bill the Lizard♦ Nov 24 '11 at 13:55" – peter_budo Jul 02 '13 at 09:17

1 Answers1

10

You just need to implement MediaScannerConnectionClient in your activity and after that you have to give the exact path of one of the file inside that folder name here as SCAN_PATH and it will scan all the files containing in that folder and open it inside built in gallery. So just give the name of you folder and you will get all the files inside including video. If you want to open only images change FILE_TYPE="image/*"

public class sdActivity extends Activity implements MediaScannerConnectionClient{
    public String[] allFiles;
private String SCAN_PATH ;
private static final String FILE_TYPE = "*/*";

private MediaScannerConnection conn;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    File folder = new File("/sdcard/youfoldername/");
    allFiles = folder.list();
 //   uriAllFiles= new Uri[allFiles.length];
    for(int i=0;i<allFiles.length;i++)
    {
        Log.d("all file path"+i, allFiles[i]+allFiles.length);
    }
  //  Uri uri= Uri.fromFile(new File(Environment.getExternalStorageDirectory().toString()+"/yourfoldername/"+allFiles[0]));
    SCAN_PATH=Environment.getExternalStorageDirectory().toString()+"/yourfoldername/"+allFiles[0];
    Log.d("SCAN PATH", "Scan Path " + SCAN_PATH);
    Button scanBtn = (Button)findViewById(R.id.scanBtn);
    scanBtn.setOnClickListener(new OnClickListener(){
    @Override
    public void onClick(View v) {
        startScan();
    }});
    }
    private void startScan()
    {
    Log.d("Connected","success"+conn);
    if(conn!=null)
    {
    conn.disconnect();
    }
    conn = new MediaScannerConnection(this,this);
    conn.connect();
    }
@Override
public void onMediaScannerConnected() {
    Log.d("onMediaScannerConnected","success"+conn);
    conn.scanFile(SCAN_PATH, FILE_TYPE);    
}
@Override
public void onScanCompleted(String path, Uri uri) {
    try {
        Log.d("onScanCompleted",uri + "success"+conn);
        if (uri != null) 
        {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(uri);
        startActivity(intent);
        }
        } finally 
        {
        conn.disconnect();
        conn = null;
        }
       }
}
PiyushMishra
  • 5,743
  • 6
  • 37
  • 57