안 드 로 이 드 가 향상 시 킨 모 바 일 게임 의 모 의 조작
5200 단어 Android
현재 대부분의 안 드 로 이 드 모 바 일 게임 은 안 드 로 이 드 시스템 의 텔레비전 단말기 에서 실 행 될 수 있 는데 그 중에서 일부 모 바 일 게임 은 원생 지원 손잡이(예 를 들 어 MOGA 손잡이)로 이 부분 게임 은 텔레비전 게임 으로 할 수 있다.그러나 다른 모 바 일 게임(사격,자동차 경주,동작 등 게임)이 텔레비전 에서 하려 면 조작 모드 를 수정 하고 터치 스크린 조작 을 손잡이 실체 키 조작 으로 바 꿔 야 한다.
본 고 는 주로/system/bin/아래 의 Input 명령 을 어떻게 사용 하 는 지 설명 합 니 다.본문 전체 코드 는 여 기 를 클릭 하 십시오본 사이트 다운로드
프로그램 실행 결 과 는 다음 그림 과 같 습 니 다.
본 논문 의 핵심 RootCommand.자바 의 코드 는 다음 과 같 습 니 다.코드 를 전체 정적 방법 으로 농축 하 는 것 을 권장 하지 않 습 니 다.여기 서 process 와 os 라 는 두 변수의 생명 주 기 를 app 이 끝 날 때 까지 유지 하면 여러 번 초기 화/방출 하 는 시간 을 줄 일 수 있 습 니 다.구체 적 인 코드 는 다음 과 같다.
package com.hellogv.slinput;
import java.io.DataOutputStream;
import java.io.IOException;
import android.util.Log;
/**
* su input
* init() exit(), run()。
* @author hellogv
*
*/
public class RootCommand {
private String TAG="RootCommand";
private Process process = null;
private DataOutputStream os = null;
public void init() {
try {
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
} catch (IOException e) {
Log.e(TAG, getExceptionMessage(e));
}
}
/**
* shell , root
*
* @param command
* @return
*/
public boolean run(String command) {
try {
os.writeBytes(command + "
");
os.flush();
} catch (Exception e) {
Log.e(TAG, getExceptionMessage(e));
return false;
}
return true;
}
/**
* shell , root
*
* @param command
* @return
*/
public void release() {
try {
os.writeBytes("exit
");
os.flush();
process.waitFor();
} catch (Exception e) {
Log.e(TAG, getExceptionMessage(e));
} finally {
try {
if (os != null) {
os.close();
}
process.destroy();
} catch (Exception e) {
}
}
}
private static String getExceptionMessage(Exception ex){
String result="";
StackTraceElement[] stes = ex.getStackTrace();
for(int i=0;i<stes.length;i++){
result=result+stes[i].getClassName()
+ "." + stes[i].getMethodName()
+ " " + stes[i].getLineNumber() +"line"
+"\r
";
}
return result;
}
}
RootCommand 를 호출 하 는 코드 는 다음 과 같 습 니 다.input 명령 의 사용 형식 은 코드 를 참조 하 십시오.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rootCommand.init();
// Home
btnTestKey = (Button) this.findViewById(R.id.btnTestKey);
btnTestKey.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// :input keyevent keycode
rootCommand.run("/system/bin/input keyevent "+KeyEvent.KEYCODE_HOME);
}
});
//
btnTestSwipe= (Button) this.findViewById(R.id.btnTestSwipe);
btnTestSwipe.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
int x2 = MainActivity.this.getWindow().getDecorView().getWidth() - 10;
//
rootCommand.run("/system/bin/input keyevent "+KeyEvent.KEYCODE_HOME);
// , :input swipe x1 y1 x2 y2
for(int i=0;i<4;i++){
rootCommand.run("/system/bin/input swipe 10 300 "+x2+" 400");
rootCommand.run("/system/bin/input swipe "+x2+" 300 10 400");
}
}
});
//
btnTestTap= (Button) this.findViewById(R.id.btnTestTap);
btnTestTap.setOnClickListener( new OnClickListener(){
@Override
public void onClick(View v) {
int[] location = new int[2];
btnTestSwipe.getLocationOnScreen(location);
int x = location[0]+btnTestSwipe.getWidth()/2;
int y = location[1]+btnTestSwipe.getHeight()/2;
// btnTestTap
rootCommand.run("/system/bin/input tap "+x+" "+y);
}
});
//
btnExit = (Button) this.findViewById(R.id.btnExit);
btnExit.setOnClickListener( new OnClickListener(){
@Override
public void onClick(View v) {
rootCommand.release();
MainActivity.this.finish();
}
});
// root , root
if(RootTools.isRootAvailable()==false){
Toast.makeText(this, " ROOT 。", Toast.LENGTH_SHORT).show();
this.finish();
}
}
관심 있 는 친 구 는 이 인 스 턴 스 의 전체 코드 를 다운로드 하여 디 버 깅 을 할 수 있 으 며,여러분 의 안 드 로 이 드 프로 그래 밍 에 큰 도움 이 될 것 이 라 고 믿 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Bitrise에서 배포 어플리케이션 설정 테스트하기이 글은 Bitrise 광고 달력의 23일째 글입니다. 자체 또는 당사 등에서 Bitrise 구축 서비스를 사용합니다. 그나저나 며칠 전 Bitrise User Group Meetup #3에서 아래 슬라이드를 발표했...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.