Press "Enter" to skip to content

[카테고리:] 안드로이드

안드로이드에서 adb shell로 apk 추출하기

설치된 패키지 찾기

adb shell
pm list packages -f | grep "패키지 이름 등등 검색어"

설치된 패키기 찾기(전체 패키지를 페이지단위로 보여주기)

adb shell pm list packages | more

실제로 해보기(볼드체만이 입력 명령임-예제로 카카오톡 apk를 추출해 보겠습니다.)
명령 프롬프트 창에서 작업합니다.

C:\Temp> adb shell
beryllium:/ $ 
beryllium:/ $ pm list packages -f | grep kakao
package:/data/app/com.kakao.talk-wuLPpyq8x_j7b7eUR_6vGg==/base.apk=com.kakao.talk
package:/data/app/com.kakao.taxi-_6AcQILJ-fTin_aO2jbH_Q==/base.apk=com.kakao.taxi
beryllium:/ $ exit
C:\Temp>adb pull /data/app/com.kakao.talk-wuLPpyq8x_j7b7eUR_6vGg==/base.apk
 /data/app/com.kakao.talk-wuLPpyq8x_j7b7eUR_6vGg==/base.apk: 1 file pulled. 36.5 MB/s (96969655 bytes in 2.532s)
C:\Temp>

C:\Temp 폴더에 base.apk 라는 이름으로 카카오톡 apk가 추출되었습니다.

블루투스 Characteristic 조회

{
    List<BluetoothGattService> gattServices = bBluetoothLeService.agetInstance().lmBGatt.getServices();

    if ( gattServices == null )
    {
        return;
    }
    String uuid = null;
    String unknownServiceString = "모르는 서비스";
    String unknownCharaString = "모르는 특성";

    ArrayList<HashMap<String, String>> gattServiceData = new ArrayList<HashMap<String, String>>();
    ArrayList<ArrayList<HashMap<String, String>>> gattCharacteristicData = new ArrayList<ArrayList<HashMap<String, String>>>();
    ArrayList<ArrayList<BluetoothGattCharacteristic>> mGattCharacteristics = new ArrayList<ArrayList<BluetoothGattCharacteristic>>();

    // Loops through available GATT Services.
    for ( BluetoothGattService gattService : gattServices )
    {
        HashMap<String, String> currentServiceData = new HashMap<String, String>();
        uuid = gattService.getUuid().toString();

        gattServiceData.add( currentServiceData );

        ArrayList<HashMap<String, String>> gattCharacteristicGroupData = new ArrayList<HashMap<String, String>>();
        List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();
        ArrayList<BluetoothGattCharacteristic> charas = new ArrayList<BluetoothGattCharacteristic>();

        // Loops through available Characteristics.
        for ( BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics )
        {
            charas.add( gattCharacteristic );
            HashMap<String, String> currentCharaData = new HashMap<String, String>();
            uuid = gattCharacteristic.getUuid().toString();
            gattCharacteristicGroupData.add( currentCharaData );

            List<BluetoothGattDescriptor> diss = gattCharacteristic.getDescriptors();
            for ( BluetoothGattDescriptor d : diss )
            {

                uuid = d.getUuid().toString();
                uuid = d.getUuid().toString();


            }
        }
        mGattCharacteristics.add( charas );
        gattCharacteristicData.add( gattCharacteristicGroupData );
    }
}

Android에서 JSON 데이터를 송수신

Android에서 JSON 데이터를 송수신하기 위해서 HttpURLConnection을 사용하여 만든 함수 입니다.

  • serverURL : JSON 요청을 받는 서버의 URL
  • postPara : POST 방식으로 전달될 입력 데이터
  • flagEncoding : postPara 데이터의 URLEncoding 적용 여부
  • 반환 데이터 : 서버에서 전달된 JSON 데이터
public static String getJson(String serverUrl, String postPara, boolean flagEncoding) throws Exception {
         URL url = null;
         HttpURLConnection conn = null;
         PrintWriter postReq = null;
         BufferedReader postRes = null;
         StringBuilder json = null;
         String line = null;

json = new StringBuilder();
try {
    if (flagEncoding) {
        postPara = URLEncoder.encode(postPara);
    }

    url = new URL(serverUrl);
    conn = (HttpURLConnection) url.openConnection();
    conn.setDoOutput(true);
    conn.setUseCaches(false);
    conn.setRequestMethod("POST");
    conn.setRequestProperty("Content-Type", "text/plain");
    conn.setRequestProperty("Content-Length", 
                                               Integer.toString(postPara.length()));
    conn.setDoInput(true);

    postReq = new PrintWriter(
                      new OutputStreamWriter(conn.getOutputStream(), "UTF-8"));
    postReq.write(postPara);
    postReq.flush();

    postRes = new BufferedReader(
                     new InputStreamReader(conn.getInputStream(), "UTF-8"));
    while ((line = postRes.readLine()) != null){
        json.append(line);
    }
    conn.disconnect();
} catch (MalformedURLException ex) {
    throw new Exception(ex.getMessage());
} catch (IOException ex) {
    throw new Exception(ex.getMessage());
} catch (Exception ex) {
    throw new Exception(ex.getMessage());
}
return json.toString(); 
}   

출처 : http://www.jopenbusiness.com/tc/oss/entry/Android에서-Json-사용하여-통신하기-1?category=15

안드로이드 개발할때 WI-FI로 연결하기 ( adb 무선 연결 )

출처 : http://kmshack.tistory.com/364


개발할때 USB안쓰고 WI-FI로 써야 겠다고 생각!

방법은 아주 간단하다.

ADB  무선 연결 / 무선 접속

일단은 을 USB에 연결 후 TCPIP 포트를 세팅한다. 

ADB명령을 통해 포트 7777로 변경한다. (숫자는 아무거나 상관 없음)

#adb tcpip 7777


그리고 이제 USB안녕! 이제 USB 선정리 해버리자!! 폰과 컴퓨터가 같은 네트워크가 연결 된 환경에서 폰의 WIFI주소(설정 – WIFI설정 – 연결된 WIFI를 통해 알수 있음)를 알아서, 아래 명령을 입력 하자.


#adb connect xxx.xxx.xxx.xxx:7777


지저분한 USB안녕?

하지만 베터리 어쩌지…


쓸때만 켜고 제니모션 에뮬레이터를 써야 겠다.

참고로 연결을 끊을때는

# adb disconnect xxx.xxx.xxx.xxx:7777