Android MMS意图与视频文件和正文文本

时间:2014-06-19 07:43:23

标签: android android-intent message mms

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

此代码使用图像和文本发送mms。

但是如何发送视频文件而不是图像?

2 个答案:

答案 0 :(得分:0)

尝试以下代码: -

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

答案 1 :(得分:0)

我假设你想从你的记忆中挑选你的视频。然后,首先你必须导入:

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

    }
}
}

在Manifest中插入权限:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />