【黑科技】钉钉自动打卡

所需环境:
1、JDK
2、Android SDK

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class DDingAutoClock {

    public static void main(String[] args) {
        Timer timer = new Timer();
        timer.schedule(new Task(), 60 * 1000);
    }

    static class Task extends TimerTask {
        public void run() {
            String str = getCurrentTime();
            if(str.equals("08:00")){
                System.out.println("定时任务执行");
                //启动叮叮
                try {
                    execCommand("adb wait-for-device");
                    execCommand("adb shell am start -n com.alibaba.android.rimet/com.alibaba.android.rimet.biz.SplashActivity");
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

        }
    }

    public static String getCurrentTime(){
        SimpleDateFormat formatter   =   new   SimpleDateFormat   ("HH:mm");
        Date curDate   =   new   Date(System.currentTimeMillis());//获取当前时间
        String   str   =   formatter.format(curDate);
        System.out.println(str);
        return str;
    }

    public static void execCommand(String command) throws IOException {
        // start the ls command running
            //String[] args =  new String[]{"sh", "-c", command};
        Runtime runtime = Runtime.getRuntime();  
        Process proc = runtime.exec(command);        //这句话就是shell与高级语言间的调用
                                                     //如果有参数的话可以用另外一个被重载的exec方法
        //实际上这样执行时启动了一个子进程,它没有父进程的控制台
        //也就看不到输出,所以我们需要用输出流来得到shell执行后的输出
        InputStream inputstream = proc.getInputStream();
        InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
        BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
        // read the ls output
        String line = "";
        StringBuilder sb = new StringBuilder(line);
        while ((line = bufferedreader.readLine()) != null) {
            //System.out.println(line);
                sb.append(line);
                sb.append("\n");
        }

        //使用exec执行不会等执行成功以后才返回,它会立即返回
        //所以在某些情况下是很要命的(比如复制文件的时候)
        //使用wairFor()可以等待命令执行完成以后才返回
        try {
            if (proc.waitFor() != 0) {
                System.out.println(proc.exitValue());
            }
        }
        catch (InterruptedException e) {  
            System.err.println(e);
        }
    }
}
  • 4
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值