兩步實現安卓手機秒變網絡攝像頭

今天大概是興趣加技術篇,程序員不寫點有趣的代碼,怕是很難在女票和家人面前秀出科技感。
GITHUB:
https://github.com/AndroidMsky/RootPlay

這裏寫圖片描述

如GIF所示,自動接起QQ電話。

QQ視頻來電自動接起來,微信視頻電自動接起來。

首先你需要兩個硬件設備
1.一步Root了的,並且安裝手機QQ的安卓手機。
2.如果像文檔一點你可能需要一個手機支架。

兩步邏輯很簡單:
1.通過BroadcastReceiver獲取亮屏幕的廣播。
2.通過shell input 命令去滑動接起視頻電話。

1.寫一個BroadcastReceiver監控的廣播是Intent.ACTION_SCREEN_ON也就是屏幕被點亮後並執行我們設定好的shell命令:

BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(final Context context, final Intent intent) {
                Log.d(TAG, "onReceive");
                String action = intent.getAction();

                if (Intent.ACTION_SCREEN_ON.equals(action)) {
                    Log.d(TAG, "screen on");
                    try {
                        if (KAI)
                            Tools.doCmds("input swipe 170 1200 600 1200");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }


                } 
            }
        };

        registerReceiver(mBatInfoReceiver, filter);
    }

2.就是讓手機去執行shell腳本直接調工具類就好啦。
Tools.doCmds(“input swipe 170 1200 600 1200”);

public static void doCmds(String cmds) throws Exception {
        Process process = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(process.getOutputStream());
        os.writeBytes(cmds + "\n");
        os.writeBytes("exit\n");
        os.flush();
        os.close();

        process.waitFor();
    }

解釋一下:
input swipe 170 1200 600 1200意思就是從(170,1200)滑動到(600,1200),大概就是來電話那個滑動按鈕,手機分辨率不通大家可以根據不通的分辨率去獲取一下這個座標值。如果你想更友好的話也可以去讓用戶去手動設置這兩個座標值,因爲shell input命令是個字符串,根據用戶的輸入去拼接一下就好了。
分享一些常用的input命令:

//休眠3秒
adb shell sleep 3
//按下home鍵還有很多物理按鍵都是這麼調用
adb shell input keyevent 3
//從550 1000滑動到550 1100
adb shell input swipe 550 1000 550 1100
//點擊事件
adb shell input tap 118 1800
//輸入字符串 這個貌似不支持中文,一般會喚起手機輸入法肯定會改變
//其它節目元素的位置,所以使用時候已定要小心哦。
adb shell input text zaiganmane

這是我寫的一小段QQ聊天命令。沒時間陪GF聊天的可以好好發掘發掘。

adb shell input text zainma
adb shell input tap 118 1800
adb shell input tap 967 1600
adb shell sleep 30
adb shell input text haode
adb shell input tap 118 1800
adb shell input tap 967 1600
adb shell sleep 10
adb shell input text wufanchilama
adb shell input tap 118 1800
adb shell input tap 967 1600
adb shell sleep 10
adb shell input text nabucuoo
adb shell input tap 118 1800
adb shell input tap 967 1600
adb shell sleep 10
adb shell input text heihei
adb shell input tap 118 1800
adb shell input tap 967 1600

不要忘了加個是否自動接聽的開關一個布爾值控制一下就好了:

    public void on1(View v) {


        KAI = true;
        mTextView.setText("is on");


    }

    public void on2(View v) {

        KAI = false;
        mTextView.setText("is off");

    }

然後是一定讓QQ和我們都應用都在後臺白名單裏,避免被殺死。筆者用自己小米MAX和MX2,紅米note3。親測24全體小時有效
這裏寫圖片描述

由於沒有判斷是誰來視頻電話建議用QQ小號,只有自己爲好友,免得誰來電都會接起來。
另外使用Accessibility可能可以優化該一些問題,這裏不做詳解。
不過筆者認爲,打造一個網絡攝像頭,秀一下科技。這篇的技術就夠啦。
看看家中的阿貓阿狗,檢查檢查你加班的時候女票在幹嘛。

家中一愛犬小葡萄,上個月走啦,T T

筆者和家人心裏甚是難過,也藉此文悼念一下我的小葡萄一路走好。

歡迎關注作者。歡迎評論討論。歡迎拍磚。

如果覺得這篇文章對你有幫助 歡迎打賞,

歡迎star,Fork我的github。
https://github.com/AndroidMsky
喜歡作者的也可以Follow。也算對作者的一種支持。

本文Github代碼鏈接
https://github.com/AndroidMsky/RootPlay

這裏寫圖片描述

博主原創未經允許不許轉載。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章