I have this code :
Activity 1
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == RESULT_OK) {
// Get the Uri of the selected file
Uri fileUri = data.getData();
Log.d("File", "File Uri: " + fileUri.toString());
Intent intent = new Intent(getContext(),activity_file_sharing.class);
intent.putExtra("Filepath", fileUri);
startActivity(intent);
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
In activity_file_sharing
Bundle extras = getIntent().getExtras();
if (extras != null && extras.containsKey("Filepath")) {
FPath = Uri.parse(getIntent().getStringExtra("Filepath").toString());
}
FPath = Uri.parse(getIntent().getStringExtra("Filepath").toString());
I am always getting a null reference on the line above , i can't figure out what is the problem
I hope you guys can help
Save it as a String:
Intent intent = new Intent(getContext(),activity_file_sharing.class);
intent.putExtra("Filepath", fileUri.toString());
startActivity(intent);
Related
It always changes into another activity when speech recognition is done
This is my code. What must be the problem?
I can get the result from speech recog.when it is done but it automatically changes to CropActivity
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQ_CODE_SPEECH_INPUT) {
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
m_edtInputText.setText(result.get(0));
m_mic.setVisibility(View.VISIBLE);
sttProgress.setVisibility(View.INVISIBLE);
}
}
if (resultCode == Activity.RESULT_OK) {
Uri imageUri = getPickImageResultUri(data);
CropImage.activity(imageUri)
.setGuidelines(CropImageView.Guidelines.ON)
.start(this);
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_in_right);
}
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == Activity.RESULT_OK) {
Uri resultUri = result.getUri();
Intent intent = new Intent(this, CropActivity.class);
intent.putExtra("imageUri", resultUri);
startActivity(intent);
} else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
Exception error = result.getError();
}
}
if(requestCode == MY_CHECK_DATA){
if(resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS){
m_TTS = new TextToSpeech(this,this);
}
else
{
Intent m_installTTSIntent = new Intent();
m_installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(m_installTTSIntent);
}
}
}
I have this code :
public static final int RESULT_OK = -1;
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == RESULT_OK) {
// Get the Uri of the selected file
Uri fileUri = data.getData();
File F = new File(fileUri.getPath());
Log.d("File", "File Uri: " + fileUri.toString());
Intent intent = new Intent(getContext(),activity_file_sharing.class);
intent.putExtra("Filepath", fileUri.toString());
startActivity(intent);
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
F.length() always return 0 i need to path the size of the selected file to the other activity
can anyone help
Please, check this link:
how do I get file size of temp file in android?
Try this:
File file = new File(selectedPath);
int file_size = Integer.parseInt(String.valueOf(file.length()/1024));
I'm trying to save a photo that I have already captured in my application (to use it later like as an icon for my contact) but I don't know if I must change it from uri to bitmap or any other type. I would like to save it as a .png like my others photos
Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("image/*");
startActivityForResult(galleryIntent, 1020);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1020 && resultCode == RESULT_OK) {
mImageUri = data.getData();
Uri mImageUri2 = mImageUri;
Uri aux1=mImageUri;
Bitmap foto = photoUtils.getImage(aux1);
Drawable fotofinal =new BitmapDrawable(getResources(),foto);
Thanks for the help.
I'm trying to take a picture with my app, save it and retrieve the url. Currently I have:
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, TAKE_PICTURE);
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode)
{
case TAKE_PICTURE:
{
if (resultCode == RESULT_OK)
{
File file = new File(getPath(data.getData()));
Date dt = new Date(file.lastModified());
String datum = dt.toLocaleString();
Comment_Resource photo = new Comment_Resource(file.getAbsolutePath(), datum, true);
}
break;
}
}
}
this works on some phones but a lot of phones don't save the picture causing a nullpointer.
try this:
Uri uri = Uri.fromFile(file);
I have this code:
startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE), CAMERA_IMAGE);
That allows that user to take a photo. Now how would I get the Uri of that photo in onActivityResult? Is it an Intent extra? Is it through Intent.getData()?
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
Uri u = intent.getData();
}
By the way... there's a bug with that intent in some devices. Take a look at this answer to know how to workaround it.
Instead of just launching the intent, also make sure to tell the intent where you want the photo.
Uri uri = Uri.parse("file://somewhere_that_you_choose");
Intent photoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
photoIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(photoIntent, CAMERA_IMAGE);
Then when you get your onActivityResult() method called, if it was a success just open a stream to the URI and it should all be set.
Uri uri = null;
if(requestCode == GALLERY_INTENT && resultCode == RESULT_OK){
uri = data.getData();
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
Uri fileUri = Utils.getUri(getActivity(), photo);
}
}
public String getRealPathFromURI (Uri contentUri) {
String path = null;
String[] proj = { MediaStore.MediaColumns.DATA };
Cursor cursor = getActivity().getContentResolver().query(contentUri, proj, null, null, null);
if (cursor.moveToFirst()) {
int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
path = cursor.getString(column_index);
}
cursor.close();
return path;
}