다음지도 api가 안드로이드 adb지원 안한다니...해서 도전해보는

안드로이드 스튜디오와 녹스 연결하기

(okky의 한 댓글에서 녹스로 해보면 안되냐는 걸 봄.)

 

 

1. 녹스 설치

kr.bignox.com/

 

녹스 앱플레이어

지금까지 써본 앱플레이어중엔 녹스가 제일 좋은것 같아서 몇년 전부터 계속 애용중입니다. 앞으로도 유저 의견 많이 받아들이고 번창하시길 바랍니다 :)

kr.bignox.com

 

2. 명령 프롬프트 실행시켜 설치위치에서 nox_adb.exe connect 127.0.0.1:62001 입력. 연결 확인.

 

3. 안드로이드 스튜디오에서 Run 해보기 

4. 안된다. 여전히 안된다. 역시 녹스도 가상머신이라 안되나봄.

지오 코딩이란 무엇입니까?

지오 코딩 은 주소 (예 : '1600 Amphitheatre Parkway, Mountain View, CA')를 지리적 좌표 (예 : 위도 37.423021 및 경도 -122.083739)로 변환하는 과정으로,지도에 마커를 배치하거나지도를 배치하는 데 사용할 수 있습니다.

역 지오 코딩 은 지리적 좌표를 사람이 읽을 수있는 주소로 변환하는 프로세스입니다.

 

구글

https://developers.google.com/maps/documentation/geocoding/overview?hl=ko#ReverseGeocoding

 

Overview  |  Geocoding API  |  Google Developers

Geocoding converts addresses into geographic coordinates to be placed on a map. Reverse Geocoding finds an address based on geographic coordinates or place IDs.

developers.google.com

https://apis.map.kakao.com/web/sample/coord2addr/

다음 좌표로 주소얻기

apis.map.kakao.com/web/documentation/#services_Geocoder

 

D:\내 프로젝트 경로\app\build\intermediates\navigation_json\debug\navigation.json 

이 없다는 오류

-----> 결론 : 다운그레이드 해주기(navigation.json을 다시 받아올 수 있도록)

 

1. build.gradle 편집

 

dependencies {
        classpath 'com.android.tools.build:gradle:4.1.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

dependencies {
        classpath 'com.android.tools.build:gradle:4.0.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

 

 

2. gradle-wrapper.properties 편집

distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip

distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-bin.zip

자바 스레드랑 똑같아서...

 

1. 이미 상속받고있는 AppCompatActivity가 있으니까 Runnable 구현하기

public class MainActivity extends AppCompatActivity implements Runnable{
			// 중략
}

 

2. run() 메소드 구현하기

public class MainActivity extends AppCompatActivity implements Runnable{
	//중략
    
    @Override
    public void run() {
        while(true) {
            try {
               //반복할 부분 코드
                Thread.sleep(1000); // 밀리세컨드. 1초=1000, 10초=1000*10
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

 

3. 스레드 start() 시키기

public class MainActivity extends AppCompatActivity implements Runnable{
	 
     //생략
     
     @Override
   	 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Thread thread = new Thread(this);
        thread.start();
     	//생략
     }       
}

value-style.xml

앱테마에 추가

	<item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>

build.gradle(app 레벨)에 dependency추가

 

implementation 'androidx.core:core:1.5.0-alpha04'

1. Volley를 사용하겠다고 build.gradle에 선언해준다(매니페스트에 인터넷 사용은 당연한것!)

dependencies {

    implementation 'com.android.volley:volley:1.1.1'
    /* 생략 */
}

 

2. RequestQueue를 한번만 생성하도록 싱글톤으로 만든다

(출처 : developer.android.com/training/volley/requestqueue?hl=ko)

public class MySingleton {
        private static MySingleton instance;
        private RequestQueue requestQueue;
        private ImageLoader imageLoader;
        private static Context ctx;

        private MySingleton(Context context) {
            ctx = context;
            requestQueue = getRequestQueue();

            imageLoader = new ImageLoader(requestQueue,
                    new ImageLoader.ImageCache() {
                private final LruCache<String, Bitmap>
                        cache = new LruCache<String, Bitmap>(20);

                @Override
                public Bitmap getBitmap(String url) {
                    return cache.get(url);
                }

                @Override
                public void putBitmap(String url, Bitmap bitmap) {
                    cache.put(url, bitmap);
                }
            });
        }

        public static synchronized MySingleton getInstance(Context context) {
            if (instance == null) {
                instance = new MySingleton(context);
            }
            return instance;
        }

        public RequestQueue getRequestQueue() {
            if (requestQueue == null) {
                // getApplicationContext() is key, it keeps you from leaking the
                // Activity or BroadcastReceiver if someone passes one in.
                requestQueue = Volley.newRequestQueue(ctx.getApplicationContext());
            }
            return requestQueue;
        }

        public <T> void addToRequestQueue(Request<T> req) {
            getRequestQueue().add(req);
        }

        public ImageLoader getImageLoader() {
            return imageLoader;
        }
    }

 

3. 사용하고 싶은 곳에서 호출한다

3-1. 이렇게 위에서 만든 싱글톤으로 사용하거나

RequestQueue queue = MySingleton.getInstance(this.getApplicationContext()).
        getRequestQueue();

StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
                new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            // Display the first 500 characters of the response string.
            textView.setText("Response is: "+ response.substring(0,500));
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            textView.setText("That didn't work!");
        }
    });

    // Add the request to the RequestQueue.
    queue.add(stringRequest);

3-2. 그냥 바로 겟인스턴스해서 써도 된다

StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
                new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            // Display the first 500 characters of the response string.
            textView.setText("Response is: "+ response.substring(0,500));
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            textView.setText("That didn't work!");
        }
    });

    // Add the request to the RequestQueue.
    MySingleton.getInstance(this).addToRequestQueue(stringRequest);

 

4. 파라미터로 요청을 보내고 싶다면 getParmas를 사용해 Map에 담아 보내면 된다. StringRequest, POST에서만 된다. JsonRequest에서는 안됨.

StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            // Display the first 500 characters of the response string.
            textView.setText("Response is: "+ response.substring(0,500));
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            textView.setText("That didn't work!");
        }
    }){
    	@Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> params = new HashMap<>();
                params.put("key", value);
                params.put("key", value);
                
                return params;
            }
    };

    // Add the request to the RequestQueue.
    queue.add(stringRequest);

 

5. json으로 받고싶다면 argument 하나가 중간에 추가된다.

JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                
            }
        });
        
        queue.add(jsonObjectRequest);

 

 

자세한건 여기에 더 있다

https://developer.android.com/training/volley?hl=ko

안드로이드 에뮬레이터에서는 localhost나 127.0.0.1같은 주소가 안먹힌다.

(이유는 뭐 셀프로 어쩌고 해서 핑이 생겨서 어쩌고 하는 이유라는데 구글링하면 잘 나옴)

 

그래서 로컬로 에뮬레이터를 돌릴때에는

 

localhost:8080/어쩌고 대신

 

10.0.2.2:8080/어쩌고

 

를 써야한다

 

참고 :

https://developer.android.com/studio/run/emulator-networking?hl=ko

+ Recent posts