android 广播 接收短信
public class MyBroad extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
private String actions = intent.getAction();
if (actions.equals("android.provider.Telephony.SMS_RECEIVED")) {
//收到短信了
Bundle bundle = intent.getExtras();
Object[] pdus = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < messages.length; i++) {
SmsMessage ms = SmsMessage.createFromPdu((byte[])pdus[i]);
String from = ms.getDisplayOriginatingAddress().toString();
String content = ms.getMessageBody().toString();
SimpleDateFormat sf= new SimpleDateFormat("yyyy-MM-DD HH:mm:ss");
String time = sf.format(ms.getTimestampMillis());
String result = "time:"+time+" from:"+from+" content"+content;
Toast.makeText(context,result,Toast.LENGTH_SHORT).show();
}
abortBroadcast();
}
}
}
权限:<uses-permission android:name="android.permission.RECEIVE_SMS"/>
清单配置
<receiver android:name=".MyBroad" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
打电话:
<uses-permission android:name="android.permission.CALL_PHONE"/>
Intent(Intent.ACTION_CALL,Uri.parse("tel:1888888"));
其它广播ACTION
开机启动广播权限 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
开机启动<action android:name="android.intent.action.BOOT_COMPLETED"/>
关机 <action android:name="android.intent.action.ACTION_SHUTDOWN"/>
低电量 <action android:name="android.intent.action.BATTERY_LOW"/>
posted on 2017-03-02 16:37 robert_hly 阅读(324) 评论(0) 编辑 收藏 举报