zoukankan      html  css  js  c++  java
  • 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"/>
     

      





  • 相关阅读:
    Django的中间件
    Django的Models(三)
    多个SSH key对应多个Host: Github, Bitbucket
    最简单的私有库方法
    Swift compile slow 编译慢问题
    Hide Xcode8 strange log.
    cocoapods 终极方案
    "Mac OS X"想要进行更改。键入管理员的名称和密码以允许执行此操作("Mac OS X"想使用系统钥匙串)
    Xcode7下载地址
    Xcode8安装不成功, 需要升级系统. The operation couldn't be completed. cpio read error
  • 原文地址:https://www.cnblogs.com/exayong/p/6491342.html
Copyright © 2011-2022 走看看