Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("sms_body", "Hi how are you");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("/sdcard/file.gif")));
intent.setType("image/gif");
startActivity(Intent.createChooser(intent,"Send"));
this code send mms with image and text.
But how send video file instead of image ?
I assume you want to pick your video from your memory. Then, firstly you have to import:
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import java.io.File;
This is how activity looks like when you want to import video from Gallery to MMS:
public class MMS extends Activity {
// Fields
private String TAG = "MMS";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// To display current window in full screen.
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
/**
* See assets/res/layout/mms.xml for this view layout
* definition, which is being set here as the content of our screen.
*/
setContentView(R.layout.mms);
}
/*
* Open Gallery to select video to send on OnClick Event of someButton.
*/
public void onClickPicMMS(View view) {
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Video"),0);
}
/*
* Called when an activity you launched exits, giving you the requestCode you started it with, the resultCode it returned, and any additional data from it.
*/
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0 && resultCode == RESULT_OK) {
// Fetch the path of selected image.
Uri uri = data.getData();
String[] projection = { MediaStore.Video.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
cursor.moveToFirst();
String mmsvideoPath = cursor.getString(column_index);
//Call the intent to send selected video as MMS.
Intent intent = new Intent(Intent.ACTION_SEND);
File f = new File(mmsvideoPath);
intent.putExtra("sms_body", "Hi how are you");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f)); // videoUri set previously
sendIntent.setType("video/3gp");
startActivity(intent);
}
}
}
Insert the permission in Manifest:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
try below code:-
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
sendIntent.putExtra("address", "9999999999");
sendIntent.putExtra("sms_body", "if you are sending text");
final File file1 = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),"Downloadtest.3gp");
Uri uri = Uri.fromFile(file1);
Log.e("Path", "" + uri);
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
sendIntent.setType("video/3gp");
//sendIntent.setType("audio/3gp"); // sending audio
startActivity(sendIntent);
Related
I am blocked my app exit without any notification when I select images but when I select forum photo or gallery did not crashed.
I use creativesdk for photo edited.
screnshoot
package com.lamba.selfie;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.widget.ImageView;
import com.aviary.android.feather.sdk.AviaryIntent;
public class MainActivity extends AppCompatActivity {
private ImageView mResultImageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mResultImageView = (ImageView) findViewById(R.id.resultImageView);
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), 0);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
switch (requestCode) {
case 0:
Uri selectedImageUri = data.getData();
Uri imageUri = Uri.parse(getPath(selectedImageUri));
Intent imageEditorIntent = new AviaryIntent.Builder(this)
.setData(imageUri)
.build();
startActivity(imageEditorIntent);
/*case 1:
startActivityForResult(imageEditorIntent, 1);
Uri mImageUri = data.getData();
mResultImageView.setImageURI(mImageUri);
break;*/
}
}
}
public String getPath(Uri uri) {
// just some safety built in
if (uri == null) {
// TODO perform some logging or show user feedback
return null;
}
// try to retrieve the image from the media store first
// this will only work for images selected from gallery
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);
}
// this is our fallback here
return uri.getPath();
}
}
How could I fix it?
Source of the issue
You can simplify your switch statement's case 0 a bit and pass selectedImageUri directly to the AviaryIntent's setData() method.
As a result, you won't need your getPath() helper method.
Example code
Below is working code, based on your code above, that will:
Open the image source chooser immediately
Open the selected image in the Creative SDK Image Editor
Attach the edited image to the ImageView
See the comments in the example code to find where these things happen.
public class MainActivity extends AppCompatActivity {
private ImageView mSelectedImageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mSelectedImageView = (ImageView) findViewById(R.id.selectedImageView);
// Open the image source chooser immediately
Intent galleryIntent = new Intent();
galleryIntent.setType("image/*");
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(galleryIntent, "Select an image"), 0);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode) {
// Open the Creative SDK Image Editor with the chosen image
case 0:
Uri selectedImageUri = data.getData();
Intent imageEditorIntent = new AviaryIntent.Builder(this)
.setData(selectedImageUri)
.build();
startActivityForResult(imageEditorIntent, 1);
break;
// Attach the edited image to the ImageView
case 1:
Uri editedImageUri = data.getData();
mSelectedImageView.setImageURI(editedImageUri);
break;
}
}
}
// ...
}
try to change true to false on your Activity in the manifest file.
android:noHistory="true" to android:noHistory="false"
your code : galleryIntent.setAction(Intent.ACTION_GET_CONTENT)
Use this : Intent GalleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
I am trying to embed a cropper through a library in the Main activity of ABBYY Cloud OCR sample code. But no matter how hard I try, instead of executing the crop-code, it always jumps on to the next activity. Why is this happening?
package bahadur.translateit;
import abbyy.ocrsdk.android.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.net.*;
import java.io.*;
import eu.janmuller.android.simplecropimage.CropImage;
import android.os.Environment;
import android.provider.MediaStore;
import android.content.Intent;
import android.database.Cursor;
import android.view.View;
public class MainActivity extends Activity {
private final int TAKE_PICTURE = 0;
private final int SELECT_FILE = 1;
private String resultUrl = "result.txt";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void captureImageFromSdCard( View view ) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, SELECT_FILE);
}
public static final int MEDIA_TYPE_IMAGE = 1;
private static Uri getOutputMediaFileUri(){
return Uri.fromFile(getOutputMediaFile());
}
/** Create a File for saving an image or video */
private static File getOutputMediaFile(){
// To be safe, you should check that the SDCard is mounted
// using Environment.getExternalStorageState() before doing this.
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "TranlateIt!");
// This location works best if you want the created images to be shared
// between applications and persist after your app has been uninstalled.
// Create the storage directory if it does not exist
if (! mediaStorageDir.exists()){
if (! mediaStorageDir.mkdirs()){
return null;
}
}
// Create a media file name
File mediaFile = new File(mediaStorageDir.getPath() + File.separator + "image.jpg" );
return mediaFile;
}
public void captureImageFromCamera( View view) {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
Uri fileUri = getOutputMediaFileUri(); // create a file to save the image
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
startActivityForResult(intent, TAKE_PICTURE);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != Activity.RESULT_OK)
return;
String imageFilePath = null;
switch (requestCode) {
case TAKE_PICTURE:
imageFilePath = getOutputMediaFileUri().getPath();
// the following code for crop does not execute
Intent intent = new Intent(this, CropImage.class);
intent.putExtra(CropImage.IMAGE_PATH, imageFilePath);
intent.putExtra(CropImage.SCALE, true);
intent.putExtra("outputX", 200); //Set this to define the max size of the output bitmap
intent.putExtra("outputY", 150); //Set this to define the max size of the output bitmap
intent.putExtra(CropImage.ASPECT_X, 0);
intent.putExtra(CropImage.ASPECT_Y, 0);
break;
case SELECT_FILE:
Uri imageUri = data.getData();
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cur = managedQuery(imageUri, projection, null, null, null);
cur.moveToFirst();
imageFilePath = cur.getString(cur.getColumnIndex(MediaStore.Images.Media.DATA));
// same goes for the following chunk of code
Intent intet = new Intent(this, CropImage.class);
intet.putExtra(CropImage.IMAGE_PATH, imageFilePath);
intet.putExtra(CropImage.SCALE, true);
intet.putExtra("outputX", 200); //Set this to define the max size of the output bitmap
intet.putExtra("outputY", 150); //Set this to define the max size of the output bitmap
intet.putExtra(CropImage.ASPECT_X, 0);
intet.putExtra(CropImage.ASPECT_Y, 0);
break;
}
this runs instead
String lastfilepath = imageFilePath;
//Remove output file
deleteFile(resultUrl);
Intent results = new Intent( this, ResultsActivity.class);
results.putExtra("IMAGE_PATH", lastfilepath);
results.putExtra("RESULT_PATH", resultUrl);
startActivity(results);
}
}
from my comments, i mean somethign like this:
case TAKE_PICTURE:
imageFilePath = getOutputMediaFileUri().getPath();
Intent intent = new Intent(this, CropImage.class);
intent.putExtra(CropImage.IMAGE_PATH, imageFilePath);
intent.putExtra(CropImage.SCALE, true);
intent.putExtra("outputX", 200); //Set this to define the max size of the output bitmap
intent.putExtra("outputY", 150); //Set this to define the max size of the output bitmap
intent.putExtra(CropImage.ASPECT_X, 0);
intent.putExtra(CropImage.ASPECT_Y, 0);
startActivity(intent);// THIS is the line you are missing!
I am writing a android code to get the image location and after getting that put the physical image into a image view. SO far I have written code to open a popup window which allows user to select a file.
final int FILE_SELECT_CODE = 0;
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(Intent.createChooser(intent,
"Select a File to Upload"), FILE_SELECT_CODE);
} catch (Exception ex) {
Log.d("File upload", "error" + ex.toString());
}
Log.d("File Location", ":" + intent.getData().getPath());
I Tried this to get the location but it didnt show anything.
Now how do I get the file location and put it in a image view??
See this code for setting image in imageview.
package com.android.imagegalleray;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class ImageGalleryDemoActivity extends Activity {
private static int RESULT_LOAD_IMAGE = 1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button buttonLoadImage = (Button) findViewById(R.id.buttonLoadPicture);
buttonLoadImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
ImageView imageView = (ImageView) findViewById(R.id.imgView);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
}
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);
}
}
Try to use
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, SELECT_PICTURE);
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.
I have updated the following code to following line changes but did not work:
//set the Image location
File file = new File(Environment.getExternalStorageDirectory() + "/Skynet/images/t1.jpg" );
Uri uriTarget = Uri.fromFile(file);
I want to save the jpeg to the above directory, but do not know since it is using the media store. Any tip to do this.
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class AndroCamera extends Activity {
private static final int IMAGE_CAPTURE = 0;
private Button startBtn;
private Uri imageUri;
private ImageView imageView;
/** Called when the activity is first created.
* sets the content and gets the references to
* the basic widgets on the screen like
* {#code Button} or {#link ImageView}
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageView = (ImageView)findViewById(R.id.img);
startBtn = (Button) findViewById(R.id.startBtn);
startBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startCamera();
}
});
}
public void startCamera() {
Log.d("ANDRO_CAMERA", "Starting camera on the phone...");
String fileName = "testphoto.jpg";
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
values.put(MediaStore.Images.Media.DESCRIPTION,
"Image capture by camera");
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
imageUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, IMAGE_CAPTURE);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == IMAGE_CAPTURE) {
if (resultCode == RESULT_OK){
Log.d("ANDRO_CAMERA","Picture taken!!!");
imageView.setImageURI(imageUri);
}
}
}
}
thats because the Uri you are using is from the media manager, perhaps if you use the defined Uri you want it to be saved to, it should work.
Here is a hint:
mImageUri= Uri.fromFile( new File( Environment.getExternalStorageDirectory(),
"pic_" + String.valueOf( System.currentTimeMillis() ) + ".jpg" ) );
in this it was saved to the root, but since you are creating the file, then you can place it wherever you want to. Just make sure the directory exist otherwise create it.
And as #Simon said, make sure you have the permission to write on external storage.
Update 1:
currently you have something like:
imageUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
so the insert is only inserting the image to the MediaStore table... but if thats what you actually need, then you need to override the Data column in MediaStore.
adding on your contentValues something like this:
values.put( MediaStore.Images.ImageColumns.DATA, fullPath );
if you do not need to use the MediaStore table then there is no need to do the insert and therefore the ContentValues aren't needed.