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;
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 image to send on OnClick Event of mmsBtnMMSPic.
*/
public void onClickPicMMS(View view) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),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.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String mmsImagPath = cursor.getString(column_index);
//Call the intent to send selected image as MMS.
Intent intent = new Intent(Intent.ACTION_SEND);
File f = new File(mmsImagPath);
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f)); // imageUri set previously
intent.setType("image/jpg");
startActivity(intent);
}
}
}