开发学院手机开发Android 开发 Android发送短信与邮件 阅读

Android发送短信与邮件

 2010-11-05 00:54:29 来源:WEB开发网   
核心提示:Java代码发送短信:SmsManager smsMgr = SmsManager.getDefault();smsMgr.sendTextMessage(address, null, message, null, null);显示写短信界面:Uri smsToUri = Uri.parse("smsto:/

Java代码

发送短信:

SmsManager smsMgr = SmsManager.getDefault();

smsMgr.sendTextMessage(address, null, message, null, null);

显示写短信界面:

Uri smsToUri = Uri.parse("smsto://10086");

Intent mIntent = new Intent( android.content.Intent.ACTION_SENDTO, smsToUri );

startActivity( mIntent );

发送电子邮件:

Intent i = new Intent(Intent.ACTION_SEND);

i.putExtra(Intent.EXTRA_EMAIL, address);

i.putExtra(Intent.EXTRA_SUBJECT, filename);

i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + filename)); ;

i.setType("text/csv");

startActivity(Intent.createChooser(i, "EMail File"));

Android API - SMS handling

Many new application will use SMS as data delivery platform. Reality shows, on-demand movies etc request users to send predefined formatted SMS. Similarly some applications are coming up which sends data to user using SMS. Let’s see how such an application can be built using Android platform.

Android API support developing applications that can send and receive SMS messages. The android emulator does not support sending of the SMS currently. But the emulator can receive SMS. Lets explore the android SMS support and develop a small program that listens to the SMSes received on the device (on emulator) and will show that message as notification.

The event handling on Android is done with the help of intents and intent receivers. The intents announce (or broadcast) the event and intent receivers respond to the event. Intent receivers act as the event handlers.

Let’s define an intent receiver that can handle the SMS received event:

Code: Select all

package com.wissen.sms.receiver;

/**

* The class is called when SMS is received.

*/

public class SMSReceiver extends BroadcastReceiver {

1 2  下一页

Tags:Android 发送 短信

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
更多精彩
    赞助商链接

    热点阅读
      焦点图片
        最新推荐
          精彩阅读