Reputation: 797
package ianco.test.andrei;
import java.io.File;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class BrowsePicture extends Activity {
//YOU CAN EDIT THIS TO WHATEVER YOU WANT
private static final int SELECT_PICTURE = 1;
private String filePath;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button sButton = (Button) findViewById(R.id.button1);
sButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
File dir = new File(Environment.getExternalStorageDirectory().toString() + "/sdcard/yourfolder");
Log.d("File path ", dir.getPath());
String dirPath=dir.getAbsolutePath();
if(dir.exists() && dir.isDirectory()) {
Intent intent = new Intent(Intent.ACTION_VIEW);
// tells your intent to get the contents
// opens the URI for your image directory on your sdcard
//its upto you what data you want image or video.
intent.setType("image/*");
// intent.setType("video/*");
intent.setData(Uri.fromFile(dir));
// intent.setType("media/*");
// intent.
startActivityForResult(intent, 1);
}
else
{
showToast("No file exist to show");
}
}
//UPDATED
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
if (data==null) {
showToast("No image selected");
//finish();
}
else
{
Uri selectedImageUri = data.getData();
// String filemanagerstring = selectedImageUri.getPath();
//MEDIA GALLERY
String selectedImagePath = getPath(selectedImageUri);
if(selectedImagePath!=null)
{
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(selectedImageUri);
startActivity(intent);
}
else
{
showToast("Image path not correct");
}
}
}
}
in my code from below i have some errors:
1.super.onActivityResult(requestCode, resultCode, data);
i get The method onActivityResult(int, int, Intent) is undefined for the type Object
2.The method getPath(Uri) is undefined for the type new View.OnClickListener(){}
Upvotes: 0
Views: 1188
Reputation: 8735
It looks like you need to be more careful with your curly braces. You've defined the onActivityResult() inside of your setOnClickListener() method.
Upvotes: 2