您好,登錄后才能下訂單哦!
安卓版微信跳一跳輔助,java實(shí)現(xiàn),具體內(nèi)容如下
已經(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)求中的媒體類(lèi)型信息。 urlConn.setRequestProperty("Content-Type", "application/json"); //設(shè)置客戶端與服務(wù)連接類(lèi)型 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)靶的布局文件 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="150dp"> <RelativeLayout android:layout_width="100dp" android:layout_height="wrap_content"> <TextView android:id="@+id/tv_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true"/> <RelativeLayout android:id="@+id/rl" android:layout_width="100dp" android:layout_height="100dp" android:layout_below="@id/tv_time"> <View android:layout_width="match_parent" android:layout_height="1dp" android:layout_centerVertical="true" android:background="@android:color/black"/> <View android:layout_width="1dp" android:layout_height="match_parent" android:layout_centerHorizontal="true" android:background="@android:color/black"/> <View android:id="@+id/indicator" android:layout_width="30dp" android:layout_height="30dp" android:layout_centerInParent="true" android:background="@drawable/mid"/> </RelativeLayout> <Button android:id="@+id/btnForm" android:layout_width="50dp" android:layout_height="wrap_content" android:layout_below="@id/rl" android:onClick="setForm" android:text="form" android:textSize="8sp"/> <Button android:id="@+id/btnTo" android:layout_width="50dp" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_below="@id/rl" android:onClick="setTo" android:text="to" android:textSize="8sp"/> </RelativeLayout> </FrameLayout>
//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)容大家可以參考專(zhuān)題《微信跳一跳》進(jìn)行學(xué)習(xí)。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。