2013-07-26 21 views
-1

我想在我的應用程序中有一個按鈕,當按下時,用戶被帶到手機內置畫廊應用程序。如果可能的話,我希望用戶被帶到應用程序創建的目錄。有沒有辦法在Android中做到這一點?如果應用在進入畫廊後結束,那就沒問題了。有按鈕,可以自動將您帶到畫廊

+0

做出帶你到gallery.with點擊數事件 – Giant

+2

重複的意圖 - [如何打開通過代碼手機圖庫]( http://stackoverflow.com/questions/6016000/how-to-open-phones-gallery-through-code) – neo108

回答

0

試試這個代碼...!

Button btn =(Button)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); 

    } 
}); 
0

您可以使用意圖在android系統使用defalut畫廊和這裏的代碼是 -

按鈕GalleryButton =(按鈕)this.findViewById(R.id.galleryview); GalleryButton.setOnClickListener(新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; 
    }