【问题标题】:Android MMS Intent with with Video file and body text带有视频文件和正文的 Android MMS Intent
【发布时间】:2014-06-19 07:43:22
【问题描述】:
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"));

此代码发送带有图像和文本的彩信。

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

【问题讨论】:

  • 你找到答案了吗??

标签: android android-intent message mms


【解决方案1】:

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

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;

当您想将视频从画廊导入彩信时,Activity 的外观如下:

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" />

【讨论】:

    【解决方案2】:

    试试下面的代码:-

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-12
      相关资源
      最近更新 更多