Reputation: 4984
Hi I want to Open a image only using built in Gallery in android. Now I'm using the following code, If i click the button it shows the menu which contains the third party tools installed to open the image. I want only built-in gallery, Is there any option to hide the other Third party tools are I can open directly with Gallery without showing the menu.
package com.example.gallery;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class BrowsePicture extends Activity {
private static final int SELECT_PICTURE = 1;
Button bt;
private String selectedImagePath;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_browse_picture);
bt = (Button) findViewById(R.id.button1);
bt.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();
selectedImagePath = getPath(selectedImageUri);
}
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
}
Upvotes: 2
Views: 4275
Reputation: 379
Try to use
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, SELECT_PICTURE);
Upvotes: 6
Reputation: 2082
That's because on click of button you are passing intent in which you are setting its type intent.setType("image/*");
and intent.setAction(Intent.ACTION_GET_CONTENT);
so it will show list of app installed on device.
If you want to open only gallery direct then you should pass intent for gallery only.
Upvotes: 1