티스토리 뷰
반응형
adb를 이용한 안드로이드 쉘 사용방법(with source)
[윈도우 기준]
adb 설치
[아래 링크 참고]
https://kibua20.tistory.com/165
[다운로드 링크]
https://developer.android.com/studio/releases/platform-tools?hl=ko
-설치 후 환경 변수 설정
(제어판->시스템->고급 시스템 설정->환경변수)
-시스템 변수 path에 adb 경로 추가
-모바일 디바이스 개발자모드로 전환 후 usb 디버깅 허용
cmd 켠 채 adb devices
attached나오면 성공
이후 아래 기능 사용하면됨
#사용
#helper 코드
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MainServer.Helpers
{
public class AdbProcessHelper
{
private static AdbProcessHelper _instance { get; set; }
public static AdbProcessHelper Instance
{
get
{
return _instance ?? (_instance = new AdbProcessHelper());
}
}
public AdbProcessHelper()
{
}
Process process;
public string run(string param)
{
string msg = "";
process = new Process();
process.StartInfo.FileName = "adb";
process.StartInfo.Arguments = param;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.Start();
// 에러 메시지 읽기
string errorMessage = process.StandardError.ReadToEnd();
process.WaitForExit();
// 장치 연결 안됨 에러 체크
if (errorMessage.Contains("device not found"))
{
msg = "장치가 연결되지 않았습니다. 연결을 확인해주세요.";
}
else if (!string.IsNullOrEmpty(errorMessage))
{
// 다른 종류의 에러 메시지가 있는 경우
msg = $"ADB 실행 중 에러 발생: {errorMessage}";
}
else
{
// 에러 없이 성공적으로 실행된 경우
msg = "성공적으로 실행됨.";
}
process.Close();
Debug.WriteLine("자동 밝기 해제");
return msg;
}
//자동 밝기 해제
public string OffBrightAuto()
{
string param = $"shell settings put system screen_brightness_mode 0";
return run(param);
}
//밝기 값 조절
public string OnOffBright(bool isOn)
{
string param = $"shell settings put system screen_brightness {(isOn ? "255" : "10")}";
return run(param);
}
//카메라셔터 사운드 0
public string OffCameraShutter()
{
string param = $"shell settings put system csc_pref_camera_forced_shuttersound_key 0";
return run(param);
}
//밝기 경고음 끄기
public string OffBrightSound()
{
string param = $"shell settings put system shown_max_brightness_dialog 0";
return run(param);
}
//밝기 경고음 끄기
public string TOAwake()
{
string param = $"shell input keyevent 82";
return run(param);
}
//밝기 경고음 끄기
public string ToIDLE()
{
string param = $"shell input keyevent KEYCODE_POWER";
return run(param);
}
}
}
#풀코드
#adb #c# #wpf #android #shell
반응형
'c#' 카테고리의 다른 글
smartthings를 st 공식 api사용하지 않고, api와 같은 형태로 사용하기(api의 문제점 포함) (1) | 2024.05.07 |
---|---|
[autoHotKey/c#] 오토핫키와 c#을 이용한 화면 교체(change Topmost) with udp (0) | 2024.03.06 |
관리자 권한으로 CMD열기(배치파일) (0) | 2023.11.06 |
[c#/wpf/winform] 화면캡쳐하기 (0) | 2022.12.08 |
[c#/wpf] 윈도우 해상도 구하기(멀티 디스플레이 포함) (0) | 2022.12.08 |
댓글
반응형