package com.example.shuoya;
import java.util.Set;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;
public class Breast extends BroadcastReceiver
{
private static final String mACTION = “android.provider.Telephony.SMS_RECEIVED”;
@Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
if (intent.getAction().equals(mACTION))
{
StringBuilder sb = new StringBuilder();
Bundle bundle = intent.getExtras();
if (bundle != null)
{
Set keysSet=bundle.keySet();
for(String keyString:keysSet){
Log.d(“key”, keyString);
}
Object[] myOBJpdus = (Object[]) bundle.get(“pdus”);
SmsMessage[] messages = new SmsMessage[myOBJpdus.length];
for (int i = 0; i
{
messages[i] = SmsMessage.createFromPdu ((byte[]) myOBJpdus[i]);
}
for (SmsMessage currentMessage : messages)
{
//sb.append(“接收到来告:\n”);
//sb.append(currentMessage.getDisplayOriginatingAddress());
//sb.append(“\n——传来的短信——\n”);
sb.append(currentMessage.getDisplayMessageBody());
}
}
Toast.makeText(context, sb, Toast.LENGTH_LONG).show();
Intent i2 = new Intent(context, FuzhuActivity.class);
Bundle bundle2=new Bundle();
bundle2.putString(“SMS”, sb.toString());
i2.putExtra(“SMSS”, bundle2);
i2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/190856.html原文链接:https://javaforall.cn