android发送短信广播_发送短信

在Android中,发送短信广播可以通过以下步骤实现:

1、添加权限

在AndroidManifest.xml文件中添加以下权限:


2、创建广播接收器

创建一个名为SmsSenderBroadcastReceiver的广播接收器类,继承自BroadcastReceiver,并重写onReceive方法,在onReceive方法中,获取Intent对象,然后从Intent中获取电话号码和短信内容,使用SmsManager发送短信。

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.util.Log;
public class SmsSenderBroadcastReceiver extends BroadcastReceiver {
    private static final String TAG = "SmsSenderBroadcastReceiver";
    private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
    private static final String ACTION = "android.intent.action.MAIN";
    private static final String PACKAGE_NAME = "com.example.smssender";
    private static final String SMS_URI = "content://sms/inbox";
    private static final String SMS_NUMBER = "tel:";
    private static final String SMS_BODY = "body";
    private static final String SMS_ADDRESS = "address";
    private static final String SMS_DATE = "date";
    private static final String SMS_TYPE = "type";
    private static final String SMS_READ = "read";
    private static final String SMS_IS_NOTIFICATION = "is_notification";
    private static final String SMS_SEEN = "seen";
    private static final String SMS_ID = "_id";
    private static final String SMS_STATUS = "status";
    private static final String SMS_MESSAGE_TYPE = "message_type";
    private static final String SMS_EXPIRY = "expiry";
    private static final String SMS_FORCE_SIM_SLOT = "force_sim_slot";
    private static final String SMS_COUNTRY_ISO = "country_iso";
    private static final String SMS_ORIGINAL_ADDRESS = "original_address";
    private static final String SMS_DATA = "data";
    private static final String SMS_SUBJECT = "subject";
    private static final String SMS_USER_DATA = "user_data";
    private static final String SMS_PROTOCOL = "protocol";
    private static final String SMS_REPLY_PATH_PRESENT = "reply_path_present";
    private static final String SMS_AUTO_CREATE_CONTACT = "auto_create_contact";
    private static final String SMS_AUTO_GENERATE_SEQUENCE = "auto_generate_sequence";
    private static final String SMS_MAX_CHARS = "max_chars";
    private static final String SMS_ENCODING = "encoding";
    private static final String SMS_PICTURE_THUMBNAIL_URL = "picture_thumbnail_url";
    private static final String SMS_PICTURE = "picture";
    private static final String SMS_EXPIRYTIME = "expirytime";
    private static final String SMS_SCALE = "scale";
    private static final String SMS_MEDIA = "media";
    private static final String SMS_GEOCODED = "geocoded";
    private static final String SMS_LOCATION = "location";
    private static final String SMS_PROVIDER = "provider";
    private static final String SMS_LOCKED = "locked";
    private static final String SMS_ERROR_CODE = "error_code";
    private static final String SMS_CARRIER = "carrier";
    private static final String SMS_HAS_ANSWER = "has_answered";
    private static final String SMS_EXTRAS = "extras";
    private static final String SMS_FORCEREDIALNUMBER = "forceRedialNumber";
    private static final String SMS_FORCECONFERENCENUMBER = "forceConferenceNumber";
    private static final String SMS_FORCESIMPLECALLNUMBER = "forceSimpleCallNumber";
    private static final String SMS_BCCLISTSTRING = "bccListString";
    private static final String SMS_BCCLISTNUMBERSTRING = "bccListNumberString";
    private static final String SMS_MIMETYPE = "mimeType";
    private static final String SMS_PARTIAL = "partial";
    private static final String SMS_ADDRESSES = "addresses";
    private static final String SMS_CHARSET = "charset";
    private static final String SMS_SMTPAPIURL = "smtpapiurl";
    private static final String SMS_SMTPAPIDATA = "smtpapidata";
    private static final String SMS_SMTPAPIRESULTSTREAM = "smtpapiresultstream";
    private static final String SMS_SMTPAPIRESULTCODESTREAM = "smtpapiresultcodestream";
    private static final String SMS_SMTPAPIAUTHUSERNAME = "smtpapiauthusername";
    private static final String SMS_SMTPAPIAUTHPASSWORD = "smtpapiauthpassword";
    private static final String SMS_SMTPAPIAUTHTYPE = "smtpapiauthtype";
    private static final String SMS_SMTPAPIRECIPIENTLISTSTRING = "smtpapirecipientliststring";
    private static final String SMS_SMTPAPIRECIPIENTLISTNUMBERSTRING = "smtpapirecipientlistnumberstring";
    private static final String SMS_SMTPAPISOURCEADDRESSSTRING = "smtpapisourceaddressstring";
    private static final String SMS_SMTPAPISOURCEADDRESSNUMBERSTRING = "smtpapisourceaddressnumberstring";
    private static final String SMS_SMTPAPIDELIVERYREPORTREQUESTED = "smtpapideliveryreportrequested";
    private static final int MESSAGETYPEUNKNOWN404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040408383838383838383838383838383838383838383838383838383838383838383838383838383838383838383838383838383838383838383838383838383838383838383838383838e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e6f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9fafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafa faaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");*/
importbr>
<

public class SmsSenderBroadcastReceiver extends BroadcastReceiver {



	@Override

	public void onReceive(Context context, Intent intent) {



		// Check if the broadcast is from the system, not from an app

		if (getResultCode() != Activity.RESULT_OK) {

			return;

		}



		// Get the phone number and message content from the intent

		String phoneNumber = intent.getStringExtra(SmsManager.EXTRA_PHONE_NUMBER);

		String messageContent = intent.getStringExtra(SmsManager.EXTRA_TEXT);



		// Create a new SmsManager instance

		SmsManager smsManager = SmsManager.getDefault();



		// Send the message using the SmsManager instance

		smsManager.sendTextMessage(phoneNumber, null, messageContent, null, null);



	}

}


当前名称:android发送短信广播_发送短信
浏览路径:http://www.shufengxianlan.com/qtweb/news7/430207.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联