当前位置:   article > 正文

Auto.js 调用系统短信、电话_autojs 拨打电话

autojs 拨打电话
本文所有教程及源码、软件仅为技术研究。不涉及计算机信息系统功能的删除、修改、增加、干扰,更不会影响计算机信息系统的正常运行。不得将代码用于非法用途,如侵立删!

Auto.js 调用系统短信、电话

操作环境

  • VS Code
  • Google nexus5x
  • Auto.js Pro 7.0.4
  • win10

调用系统短信模块

  • 发送短信

    importClass(android.content.Intent);
    importClass(android.telephony.SmsManager);
    
    StringBuilder = java.lang.StringBuilder;
    Uri = android.net.Uri;
    ArrayList = java.util.ArrayList;
    List = java.util.List;
    Context = android.content.Context;
    SimpleDateFormat=java.text.SimpleDateFormat;
    Date=java.util.Date;
    Long=java.lang.Long;
    var MessageInfo;
    var list;
    
    console.show();
    
    var smsManager = android.telephony.SmsManager.getDefault();
    
    smsManager.sendTextMessage("13888888888", null, "123123",  null, null);
    toast('短信发送成功')
    console.info('短信发送成功')
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    请添加图片描述

  • 读取短信

    importClass(android.net.Uri);
    importClass(android.database.Cursor);
    importClass(android.content.ContentResolver);
    
    var SMS_INBOX = Uri.parse( "content://sms/" );
    var cr = context.getApplicationContext().getContentResolver();
    var projection=new Array("_id" ,  "address" ,  "person" , "body" ,  "date" ,  "type" );
    var cur = cr.query(SMS_INBOX, projection,  null ,  null ,  "date desc" );
    var i=0;
    while (cur.moveToNext()) {
        i=i+1;
        var number = cur.getString(cur.getColumnIndex("address"));//手机号 
        var name = cur.getString(cur.getColumnIndex("person"));//联系人姓名列表 
        var body = cur.getString(cur.getColumnIndex("body"));//短信内容
        toastLog(number);
        toastLog(name);
        toastLog(body);
        if(i>10){break;}
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
  • 监听短信

    importPackage(android.content);
    importClass(android.telephony.SmsMessage);
    
    var filter=new IntentFilter();
    
    filter.addAction("android.provider.Telephony.SMS_RECEIVED");
    
    var receiver = new JavaAdapter(android.content.BroadcastReceiver, {
      onReceive : function(context, intent) {
        var sender = null;
        var bundle = intent.getExtras();
        var format = intent.getStringExtra("format");
    
        if (bundle != null) {
            var pdus = bundle.get("pdus");
            for (object in pdus) {
              var message=SmsMessage.createFromPdu(pdus[object],format);
              sender = message.getOriginatingAddress();
              messageBody = (message.getMessageBody());
              log("发信人: " + replacepos(sender, 6, 9, "****"));
              log("短信内容: " + messageBody);
            }
        }
      }
    });
    
    context.registerReceiver(receiver,filter);
    
    setInterval(()=>{},1000);
    events.on("eixt", function () {
      context.unregisterReceiver(receiver);
    })
    
    function replacepos(text,start,stop,replacetext) {
      mystr = text.substring(0,start)+replacetext+text.substring(stop+1);
      return mystr;
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38

调用系统电话模块

  • 调用intent拨打电话
    function call(context,id, telNum){
    // id starts from zero to one
    importClass(android.content.Intent);
    importClass(android.net.Uri);
    importClass(android.content.Context);
    importClass(android.telecom.TelecomManager);
    let telecomManager = context.getSystemService(Context.TELECOM_SERVICE);
    
    if(telecomManager != null){
        let phoneAccountHandleList = telecomManager.getCallCapablePhoneAccounts();
        let intent = new Intent();
        intent.setAction(Intent.ACTION_CALL);
        intent.setData(Uri.parse("tel:" + telNum));
            intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandleList.get(id));
            app.startActivity(intent);
        }
    }
    
    call(context,0,12345678910)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

PS:需要先开权限,没有权限会报错Permission denied
开启权限:设置->应用和通知->Auto.js Pro->权限


资源下载

https://download.csdn.net/download/qq_38154948/85053497


本文仅供学习交流使用,如侵立删!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/776936
推荐阅读
  

闽ICP备14008679号