安卓版微信跳一跳輔助,java實(shí)現(xiàn),具體內(nèi)容如下
創(chuàng)新互聯(lián)的客戶來(lái)自各行各業(yè),為了共同目標(biāo),我們?cè)诠ぷ魃厦芮信浜?,從?chuàng)業(yè)型小企業(yè)到企事業(yè)單位,感謝他們對(duì)我們的要求,感謝他們從不同領(lǐng)域給我們帶來(lái)的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來(lái)驚喜。專業(yè)領(lǐng)域包括成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、成都外貿(mào)網(wǎng)站建設(shè)公司、電商網(wǎng)站開(kāi)發(fā)、微信營(yíng)銷、系統(tǒng)平臺(tái)開(kāi)發(fā)。
已經(jīng)看到網(wǎng)上有大神用各種方式實(shí)現(xiàn)了,我這是屬于簡(jiǎn)易版ADB命令式實(shí)現(xiàn)。
操作方法
1.光標(biāo)移動(dòng)到起始點(diǎn),點(diǎn)擊FORM
2.光標(biāo)移動(dòng)到目標(biāo)點(diǎn),點(diǎn)擊TO
3.小人已經(jīng)跳過(guò)去了
原理說(shuō)明
安裝APP,通過(guò)設(shè)置起點(diǎn)和目標(biāo)點(diǎn)位置,獲得彈跳的毫秒數(shù),發(fā)送請(qǐng)求到連接手機(jī)的電腦中,電腦執(zhí)行adb命令起跳。
具體實(shí)現(xiàn)
本人的測(cè)試設(shè)備是Mate9,android版本為7.0,由于在非Root環(huán)境下,普通安卓應(yīng)用并不能通過(guò)Runtime.getRuntime().exec()來(lái)點(diǎn)擊本應(yīng)用外的區(qū)域,所以將手機(jī)直接通過(guò)USB調(diào)試模式連接到電腦,在點(diǎn)擊TO按鈕后,
int a = Math.abs(mToX - mFromX); int b = Math.abs(mToY - mFromY); double c = Math.sqrt(a * a + b * b);
已知起點(diǎn)和終點(diǎn)的坐標(biāo),得到兩條直角邊長(zhǎng)度,用勾股定理很容易就求出了斜邊長(zhǎng)度,經(jīng)過(guò)測(cè)試,mate9每ms的彈跳距離是0.75像素,長(zhǎng)度除0.75得到time的毫秒數(shù),直接發(fā)起一次GET請(qǐng)求到電腦中發(fā)布的Servlet,然后電腦執(zhí)行Runtime.getRuntime().exec("adb shell input swipe 100 100 100 100 " + time)來(lái)控制起跳,一次完美的起跳就完成了。
源代碼
源代碼非常簡(jiǎn)單,就直接放在這里了
//寫(xiě)在安卓APP中的起跳 public class Jump { private static final String TAG = "Jump"; private Context mContext; private int mFromX = 0; private int mFromY = 0; private int mToX = 0; private int mToY = 0; /** * 每毫秒的距離 */ private static final double MS_DISTANCE = 0.75; private WindowManager wm; private View mIndicatorView; private View mIndicator; private WindowManager.LayoutParams params; private TextView mTv_time; public Jump(Context context) { mContext = context; init(); } private void init() { wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); mIndicatorView = LayoutInflater.from(mContext).inflate(R.layout.indicator, null, false); mIndicatorView.measure(0, 0); mIndicator = mIndicatorView.findViewById(R.id.indicator); mTv_time = mIndicatorView.findViewById(R.id.tv_time); mIndicatorView.findViewById(R.id.btnForm) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setForm(); } }); mIndicatorView.findViewById(R.id.btnTo) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setTo(); } }); mIndicatorView.setOnTouchListener(new View.OnTouchListener() { int startX; int startY; @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: startX = (int) event.getRawX(); startY = (int) event.getRawY(); break; case MotionEvent.ACTION_MOVE: int newX = (int) event.getRawX(); int newY = (int) event.getRawY(); int dx = newX - startX; int dy = newY - startY; params.x += dx; params.y += dy; wm.updateViewLayout(mIndicatorView, params); startX = (int) event.getRawX(); startY = (int) event.getRawY(); break; default: break; } return true; } }); params = new WindowManager.LayoutParams(); params.height = WindowManager.LayoutParams.WRAP_CONTENT; params.width = WindowManager.LayoutParams.WRAP_CONTENT; params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; params.format = PixelFormat.TRANSLUCENT; params.gravity = Gravity.TOP + Gravity.LEFT; params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; wm.addView(mIndicatorView, params); } public void setForm() { int[] mLocation = new int[2]; mIndicator.getLocationOnScreen(mLocation); int wOffset = mIndicator.getMeasuredWidth() / 2; int hOffset = mIndicator.getMeasuredHeight() / 2; mFromX = mLocation[0] + wOffset; mFromY = mLocation[1] + hOffset; } public void setTo() { int[] mLocation = new int[2]; mIndicator.getLocationOnScreen(mLocation); int wOffset = mIndicator.getMeasuredWidth() / 2; int hOffset = mIndicator.getMeasuredHeight() / 2; mToX = mLocation[0] + wOffset; mToY = mLocation[1] + hOffset; int a = Math.abs(mToX - mFromX); int b = Math.abs(mToY - mFromY); double c = Math.sqrt(a * a + b * b); final int time = (int) (c / MS_DISTANCE); mTv_time.setText(String.valueOf(time)); mFromX = 0; mFromY = 0; mToX = 0; mToY = 0; new Thread(new Runnable() { @Override public void run() { requestGet(time); } }).start(); } private void requestGet(int time) { try { StringBuilder requestUrl = new StringBuilder("http://192.168.1.140:8080/jump/JumpTime").append("?").append("time=").append(time); // 新建一個(gè)URL對(duì)象 URL url = new URL(requestUrl.toString()); // 打開(kāi)一個(gè)HttpURLConnection連接 HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); // 設(shè)置連接主機(jī)超時(shí)時(shí)間 urlConn.setConnectTimeout(5 * 1000); //設(shè)置從主機(jī)讀取數(shù)據(jù)超時(shí) urlConn.setReadTimeout(5 * 1000); // 設(shè)置是否使用緩存 默認(rèn)是true urlConn.setUseCaches(true); // 設(shè)置為Post請(qǐng)求 urlConn.setRequestMethod("GET"); //urlConn設(shè)置請(qǐng)求頭信息 //設(shè)置請(qǐng)求中的媒體類型信息。 urlConn.setRequestProperty("Content-Type", "application/json"); //設(shè)置客戶端與服務(wù)連接類型 urlConn.addRequestProperty("Connection", "Keep-Alive"); // 開(kāi)始連接 urlConn.connect(); // 判斷請(qǐng)求是否成功 if (urlConn.getResponseCode() == 200) { // 獲取返回的數(shù)據(jù) Log.e(TAG, "Get方式請(qǐng)求成功,result--->"); } else { Log.e(TAG, "Get方式請(qǐng)求失敗"); Log.e(TAG, urlConn.getResponseMessage()); } // 關(guān)閉連接 urlConn.disconnect(); } catch (Exception e) { Log.e(TAG, e.toString()); } } }
//標(biāo)靶的布局文件
//Servlet文件 public class Jump extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { int time = Integer.parseInt(req.getParameter("time")); Runtime.getRuntime().exec("adb shell input swipe 100 100 100 100 " + time); } }
以上就是此Java版跳一跳輔助的核心內(nèi)容,從此制霸排行榜不是夢(mèng)φ(>ω<*)--->(告訴一個(gè)秘密:跳太多分?jǐn)?shù)會(huì)被直接刪除的喲  ̄へ ̄)
更多內(nèi)容大家可以參考專題《微信跳一跳》進(jìn)行學(xué)習(xí)。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。