android 发送短信,彩信,邮件代码

时间:2021-11-02 08:55:35

1:发送短信

            String body=”this is mms demo”;
           Intent mmsintent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(”smsto”, number, null));
           mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);
           mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, true);
           mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, true);
            startActivity(mmsintent);


2:发送彩信

           StringBuilder sb = new StringBuilder();
            sb.append(”file://”);
            sb.append(fd.getAbsoluteFile());
            Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(”mmsto”, number, null));
            // Below extra datas are all optional.
            intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT, subject);
            intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);
            intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI, sb.toString());
            intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, composeMode);
            intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, exitOnSent);
            startActivity(intent);


3:发送Mail

             mime = “img/jpg”;
            shareIntent.setDataAndType(Uri.fromFile(fd), mime);
            shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fd));
            shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
            shareIntent.putExtra(Intent.EXTRA_TEXT, body);

 

转帖:http://hi.baidu.com/jiang_yy_jiang/blog/item/72191b00b7efa002738b6543.html

--------------------------------------------------------------------------------------------------------------------------------

windows上用eclipse开发和 使用unix环境开发是不一样的,windows上使用下面的就可以发送了,注意自己修改下。
Intent intent = new Intent(Intent.ACTION_SEND);           
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);          
            intent.putExtra("address", phnumber);
            intent.putExtra("compose_mode", false);
        intent.putExtra("exit_on_sent", true);
        intent.putExtra("subject", "彩信测试");
        intent.putExtra("sms_body", "this is mms send auto ");
        intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/ima.jpg"));
        intent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
            intent.setType("image/jpeg");
           
            startActivity(Intent.createChooser(intent,"Send MMS To"));

 

转帖:http://www.eoeandroid.com/thread-21150-1-1.html

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

发送邮件的时候:no application can perform this action 或者 没有应用程序可执行此操作,

如下代码可解决:

String mailId=(String)ContactUs.this.getString(R.string.contactus8); Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts( 
"mailto",mailId, null));
//emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{mailId});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,body);
startActivity(emailIntent);

转贴:  http://www.coderanch.com/t/520651/Android/Mobile/no-application-perform-action-when