Wednesday 10 August 2011

Send MMS Example


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);

}
}
}

7 comments:

  1. Hola, lo siento, pero no he podido hacer funcionar el ejemplo. Dentro del Layout MMS, que objetos tiene. boton, Label, y que es lo que lo dispara

    ReplyDelete
  2. Kindly tell me .. Where in the code are you specifying recipient number?????

    ReplyDelete
  3. hi
    i need to download full source code of MMS app.plz help me

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. please send me total source code to my mail "naveenthouti37@gmail.com"

    ReplyDelete
  6. please send me total source code to my mail "chinnaonly1@gmail.com"

    ReplyDelete