2. chcp 65001
3. 속성>글꼴> Lucida Console 설정
4. adb logcat
'Android 개발 > Android SDK' 카테고리의 다른 글
Avoiding Memory Leaks (0) | 2011.04.13 |
---|---|
Start Service at boot (0) | 2011.04.13 |
안드로이드(android) 다이얼로그 종류별 구현 방법 (0) | 2011.04.13 |
intent 기능 (0) | 2011.04.13 |
apk만들기 android package 생성 (0) | 2011.04.13 |
1,start web browser
-----------------------------------------------------------------------------
Under the system Intent Daquan android Android 2010-01-06 17:27:34 Read 67 Comments 0 Adjust Font Size:
1. From the google search content Intent intent = new Intent (); intent.setAction (Intent.ACT ION_WEB_SEARCH); intent.putExtra (SearchManager.QUERY, "searchString") startActivity (intent);
2. Browse the Web Uri uri = Uri.parse ( "http://www.google.com"); Intent it = new Intent (Intent.ACT ION_VIEW, uri); startActivity (it);
3. Show map Uri uri = Uri.parse ( "geo: 38.899533, -77.036476"); Intent it = new Intent (Intent.Act ion_VIEW, uri); startActivity (it);
4. Path planning Uri uri = Uri.parse ( "http://maps.google.com/maps?f=d&saddr=startLat% 20startLng & daddr = endLat% 20endLng & hl = en"); Intent it = new Intent (Intent.ACT ION_VIEW, URI); startActivity (it);
http://mapki.com/wiki/Google_Map_Parameters#Location 5. Call Uri uri = Uri.parse ( "tel: xxxxxx"); Intent it = new Intent (Intent.ACT ION_DIAL, uri); startActivity (it);
6. Call texting program Intent it = new Intent (Intent.ACT ION_VIEW); it.putExtra ( "sms_body", "The SMS text"); it.setType ( "vnd.android-dir/mms-sms"); startActivity (it);
7. Send SMS Uri uri = Uri.parse ( "smsto: 0800000123"); Intent it = new Intent (Intent.ACT ION_SENDTO, uri); it.putExtra ( "sms_body", "The SMS text"); startActivity (it); String body = "this is sms demo"; Intent mmsintent = new Intent (Intent.ACT ION_SENDTO, Uri.fromParts ( "smsto", number, null)); mmsintent.putExtra (Messaging.KEY_ACT ION_SENDTO_MESSAGE_BODY, body); mmsintent.putExtra (Messaging.KEY_ACT ION_SENDTO_COMPOSE_MODE, true); mmsintent.putExtra (Messaging.KEY_ACT ION_SENDTO_EXIT_ON_SENT, true); startActivity (mmsintent);
8. Send MMS Uri uri = Uri.parse ( "content: / / media/external/images/media/23"); Intent it = new Intent (Intent.ACT ION_SEND); it.putExtra ( "sms_body", "some text"); it.putExtra (Intent.EXTRA_STREAM, uri); it.setType ( "image / png"); startActivity (it); StringBuilder sb = new StringBuilder (); sb.append ( "file ://"); sb.append (fd.getAbsoluteFile ()); Intent intent = new Intent (Intent.ACT ION_SENDTO, Uri.fromParts ( "mmsto", number, null)); / / Below extra datas are all optional. intent.putExtra (Messaging.KEY_ACT ION_SENDTO_MESSAGE_SUBJECT, subject); intent.putExtra (Messaging.KEY_ACT ION_SENDTO_MESSAGE_BODY, body); intent.putExtra (Messaging.KEY_ACT ION_SENDTO_CONTENT_URI, sb.toString ()); intent.putExtra (Messaging.KEY_ACT ION_SENDTO_COMPOSE_MODE, composeMode); intent.putExtra (Messaging.KEY_ACT ION_SENDTO_EXIT_ON_SENT, exitOnSent); startActivity (intent);
9. Send Email
Intent it = new Intent (Intent.ACT ION_SENDTO, uri); startActivity (it); Intent it = new Intent (Intent.ACT ION_SEND); it.putExtra (Intent.EXTRA_EMAIL, "me@abc.com"); //???? it.putExtra (Intent.EXTRA_TEXT, "The email body text"); it.setType ( "text / plain"); startActivity (Intent.createChooser (it, "Choose Email Client")); Intent it = new Intent (Intent.ACT ION_SEND); String [] tos = ( "me@abc.com"); String [] ccs = ( "you@abc.com"); it.putExtra (Intent.EXTRA_EMAIL, tos); it.putExtra (Intent.EXTRA_CC, ccs); it.putExtra (Intent.EXTRA_TEXT, "The email body text"); it.putExtra (Intent.EXTRA_SUBJECT, "The email subject text"); it.setType ( "message/rfc822"); startActivity (Intent.createChooser (it, "Choose Email Client"));
it.putExtra (Intent.EXTRA_SUBJECT, "The email subject text"); it.putExtra (Intent.EXTRA_STREAM, "file: / / / sdcard/mysong.mp3"); sendIntent.setType ( "audio/mp3"); startActivity (Intent.createChooser (it, "Choose Email Client"));
10. Play Media Intent it = new Intent (Intent.ACT ION_VIEW); Uri uri = Uri.parse ( "file: / / / sdcard/song.mp3"); it.setDataAndType (uri, "audio/mp3"); startActivity (it); Uri uri = Uri.withAppendedPath (MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1"); Intent it = new Intent (Intent.ACT ION_VIEW, uri); startActivity (it);
11.uninstall apk Uri uri = Uri.fromParts ( "package", strPackageName, null); Intent it = new Intent (Intent.ACT ION_DELETE, uri); startActivity (it);
12.install apk Uri installUri = Uri.fromParts ( "package", "xxx", null); returnIt = new Intent (Intent.ACT ION_PACKAGE_ADDED, installUri); private void sendEmail(String[] address, String subject, String msg) {
Intent send = new Intent(Intent.ACTION_SEND); send.putExtra(Intent.EXTRA_EMAIL, address); send.putExtra(Intent.EXTRA_SUBJECT, subject); send.putExtra(Intent.EXTRA_TEXT, msg); send.setType("text/plain"); startActivity(Intent.createChooser(send, "MySendMail")); } --- Intent msg=new Intent(Intent.ACTION_SEND); msg.putExtra(Intent.EXTRA_EMAIL ,"testto@test.net"); msg.putExtra(Intent.EXTRA_SUBJECT, "Here is the subject for the email"); //this next line adds an attachment, but I'm having some issues with the file location msg.putExtra(Intent.EXTRA_STREAM, Uri.parse ("file://" + Environment.getExternalStorageDirectory() + "test.txt")); msg.putExtra(Intent.EXTRA_BCC, "testbcc@test.net"); msg.putExtra(Intent.EXTRA_CC, "testcc@test.net"); //This next line puts in the body of the message msg.putExtra(Intent.EXTRA_TEXT,"Attached is your file "); msg.setType("text/csv"); //Another type to try //msg.setType("message/rfc822"); startActivity(Intent.createChooser(msg, "Send Email")); |
'Android 개발 > Android SDK' 카테고리의 다른 글
Avoiding Memory Leaks (0) | 2011.04.13 |
---|---|
Start Service at boot (0) | 2011.04.13 |
안드로이드(android) 다이얼로그 종류별 구현 방법 (0) | 2011.04.13 |
logcat에서 한글사용대체하는 방법 (0) | 2011.04.13 |
apk만들기 android package 생성 (0) | 2011.04.13 |
아래에 링크로 가면 마소기사를 하나 볼 수 있다. 그리고 직접 실습한 글도 같이 볼 수 있다.
http://helloroid.tistory.com/3
여기서도 비슷하게 android application 을 작성하기 위해 어떻게 해야 하는지 알아보자.
eclipse를 사용해 간단하게 project 를 빌드 할 수도 있지만
마소에 나온 말처럼 좀 더 자세한 이해를 위해 command 를 이용해 하나 하나 짚어본다.
일단 필요한 도구부터 설치하자.
설치
Android SDK설치 (http://code.google.com/android/)
Ant 설치 (http://ant.apache.org/bindownload.cgi)
JDK 설치 (http://java.sun.com/javase/downloads/index.jsp)
JDK 는 eclipse 를 설치할 나중을 위해 1.6 이상을 추천한다.
환경설정
설치를 하고 나서는 android SDK 의 bin 의 경로를 %PATH% 에 넣어준다.
그게 싫으면 아래와 같은 .bat 를 만들어서 매번 cmd 창에서 실행해 주자.
당연한 얘기지만 아래의 경로(path) 는 알아서 수정해야 한다.
여기서 %JAVA_HOME%은 ant 에서 쓰이게 된다.
///< env.bat
set PATH=%Path%C:\Program Files\Android\android-sdk-windows-1.0_r1\tools;C:\Program Files\ant\bin;C:\Program Files\Java\jdk1.6.0_11\bin
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_11
////
프로젝트 생성
>activityCreator --out Hello com.kmaru.helloroid.Helloroid
위와 같은 command로 project를 생성할 수 있다.(위의 경우 Helloroid 라는 폴더가 생겼을 것이다.)
project는 어디에 생성해도 상관없다.
자신이 관리하기 좋은 곳에서 command를 실행하자.
다음 글에서도 Hello 로 project 생성했다는 것을 잊지 않길 바란다.
프로젝트 빌드
이경우 보통은 무리없이 실행될 수 있다. 하지만 만약에 자신의 project 가 android SDK 와 다른 드라이브를 갖고 있다면 error가 날지도 모른다.
예를 들면 android SDK 는 C:\ 에 있는데 project 폴더는 D:\에 있는 경우이다.
이건 ant에서 apkbuilder.bat 를 호출하는데 이 apkbuilder.bat 가 제대로 안만들어져서 그렇다.
아래와 같이 수정하자. 빨간부분이 추가 한 부분이다.
android
\Android\android-sdk-windows-1.0_r1\tools\apkbuilder.bat에
rem NOTICE!! if drive is different betwwen sources of activityCreate and apkbuilder.bat, there is problem. Thus, I added %~d0.
%~d0
cd %~dp0
다음엔 직접 android project를 build 해 보자.
-----------------------------------------------
android package를 만들어보자.
ant 를 사용해서 할 경우 순서대로 거치는 과정을 직접 하나 하나 해 보면서
어떠한 과정을 거치는지 아는데 의의가 있다.
대략적인 순서는
R.java 를 생성 --> compile .java --> 달빅(Dalvik)용으로 변환하기 -->package file 만들기 --> signing 하기
가 되겠다.
직접 android package 만들기
1. R.java 생성하기
1.1 R.java
먼저 R.java라는 파일을 생성해야 한다. 이 R.java 에 대한 설명은 http://code.google.com/android/intro/hello-android.html 에 나와 있다.
A project's R.java file is an index into all the resources defined in the file. You use this class in your source code as a sort of short-hand way to refer to resources you've included in your project.
요약하면, project에서 쓰이는 resource 의 index라고 할 수 있다. 실제로 위의 경로에 가보면 R.java 의 example을 보여주는데 각 변수에 해당 resource 에 대한 주소값이 할당되어 있다.
1.2 R.java 생성
aapt 라는 android sdk 안에 있는 android asset packaging tool 을 이용한다.
>aapt package -m -J src -M AndroidManifest.xml -S res -I "c:\Program Files\Android\android-sdk-windows-1.0_r1\android.jar"
이러면 project/src 에 R.java 가 생겼을 것이다.
이제 *.java 를 compile 해보자.
2. compile .java files
각 .java 에 대해 아래와 같이 명령어를 실행하면 된다. 여기서는 Hello.java 와 R.java 밖에 없기 때문에 2개의 file 만 실행한다.
>javac -d bin\classes -classpath bin\classes -bootclasspath "c:\Program Files\Android\android-sdk-windows-1.0_r1\android.jar" src\com\kmaru\helloroid\R.java
>javac -d bin\classes -classpath bin\classes -bootclassp
ath "c:\Program Files\Android\android-sdk-windows-1.0_r1\android.jar" src\com\km
aru\helloroid\Hello.java
3. .class 를 Dalvik JVM 용으로 변환하기
android 는 일반적인 JVM 을 쓰지 않는다. Dalvik 이라는 새로운 JVM을 만들어서 사용하는데 이것에 대해서 알고 싶다면 아래를 참고하자.
http://ko.wikipedia.org/wiki/%EB%8B%AC%EB%B9%85_%EA%B0%80%EC%83%81_%EB%A8%B8%EC%8B%A0
D:\Project\eclipse\Hello>dx --dex --output="D:\Project\eclipse\Hello\bin\classes.dex" --positions=lines "D:\Project\eclipse\Hello\bin\classes"
4. .apk 만들기 - package file 만들기
다음은 .apk 를 만들어야 한다. 이 .dex file 들을 하나로 묶어주는 역할을 한다고 보면 된다.
이 하나의 package가 하나의 app이 되는 것이다.
aapt의 설명은 help 에도 잘 나와 있다. aapt package 는 package와 관련된 작업을 할 때 사용한다.
D:\Project\eclipse\Hello>aapt package -f -M AndroidManifest.xml -S res -I "c:\Program Files\Android\android-sdk-windows-1.0_r1\android.jar" -F bin\Hello.apk
이제 만들어진 package 의 내용을 확인해 보자. 이때 사용하는 것이
aapt list 이다.
//.apk 내용 확인
D:\Project\eclipse\Hello>aapt list bin\Hello.apk
res/layout/main.xml
AndroidManifest.xml
resources.arsc
5. apkbuilder를 이용해 Hello-debug.apk만들기
이제 거의 다 되었다. 마지막으로 우리가 만든 package에 signing 을 해야 한다.
보통 자신이 만든 application 에 sign 을 해서 publishing 이 이루어진다.
지금 같은 경우는 test를 위해 debug 용의 debug.keystore 를 이용해 publishing 을 한 것이다.
나중에 직접 배포하게 될때는 개인의 key를 이용해야 할 것이다. 자세한 사항은 밑을 참고하자.
http://code.google.com/android/devel/sign-publish.html#signing
D:\Project\eclipse\Hello>apkbuilder d:\Project\eclipse\Hello\bin\Hello-debug.apk -z d:\Project\eclipse\Hello\bin\Hello.apk -f d:\Project\eclipse\Hello\bin\classes.dex -rf d:\Project\eclipse\Hello\src -rj d:\Project\eclipse\Hello\libs
Using keystore: C:\Documents and Settings\user\Local Settings\Application Data\Android\debug.keystore
D:\Project\eclipse\Hello>aapt list bin\Hello-debug.apk
res/layout/main.xml
AndroidManifest.xml
resources.arsc
classes.dex
META-INF/MANIFEST.MF
META-INF/CERT.SF
META-INF/CERT.RSA
여기서 주의할점은 path를 fullpath로 적어줘야 한다.
apkbuilder 가 있는 위치에서 path를 찾기 때문에 상대경로를 적으려면 apkbuilder 의 위치에서 찾아야 할 것이다.
위에서 보이는 것 처럼 apkbuilder를 사용하면 META-INF 관련 file이 더 생기게 된다.
참고로 sign 을 하지 않으면 emulator 에서도 돌아가지 않는다.
아마 설치를 하면 아래와 같은 error를 보게 될 것이다.
Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]
6. emulator 구동하기
c:\Program Files\Android\android-sdk-windows-1.0_r1\tools\emulator.exe
를 실행하면 된다. 이것도 갖가지 옵션을 붙여서 실행가능한데 옵션에 관한 설명은 아래를 참고하자.
http://code.google.com/android/reference/emulator.html#startup-options
여기서 사용할 것은 사용자가 만든 application 부분만 지우는 작업이 필요한다.
그때사용할 것이 -wipe-data라는 option이다.
>emulator -wipe-data
로 실행하면 된다.
7. .apk 설치하기
//adb install
이 emulator 에 만든 hello 라는 program을 설치 해야 한다.
이때 쓰이는 것이 android debug bridge(adb) 이다.
D:\Project\eclipse\Hello>adb install bin\Hello-debug.apk
271 KB/s (0 bytes in 4346.000s)
pkg: /data/local/tmp/Hello-debug.apk
Success
이러면 성공이다.
이 작업은 emulator가 돌고 있는 상황에서 해줘야 한다.
당연히 설치하고 난 후 바로 emulator에서 확인이 가능하다.
linux 에서 module을 올리는 작업과 비슷하다고 여기면 될 듯 하다.
'Android 개발 > Android SDK' 카테고리의 다른 글
Avoiding Memory Leaks (0) | 2011.04.13 |
---|---|
Start Service at boot (0) | 2011.04.13 |
안드로이드(android) 다이얼로그 종류별 구현 방법 (0) | 2011.04.13 |
logcat에서 한글사용대체하는 방법 (0) | 2011.04.13 |
intent 기능 (0) | 2011.04.13 |