2. Xamarin.Android
2.1 Hello Android(Xamarin.Android Application) Example
Application에 전화거는 기능을 활성화 시키자. Android Manifest안에 권한과 관련된 부분을 정의해야 하는데, 솔루션 탐색기에서 Properties를 더블클릭하고 좌측 Android Manifest를 선택 후 하단의 Permission중 “CALL_PHONE” permission을 활성화 하자.
모든 변경사항을 저장(Ctrl+Shift+S)하고 빌드하자.(Build > Rebuild Solution)
MainActivity.cs의 Label은 응용프로그램의 스크린 최상단에 디스플레이되는 텍스트이니 필요하다면 수정을 하면 된다.
[Activity(Label = "Xamarin Android", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity {
응용프로그램의 아이콘을 설정할 수 있는데 https://developer.xamarin.com/guides/android/getting_started/hello,android/Resources/XamarinAppIconsAndLaunchImages.zip 에서 아이콘 ZIP파일을 다운받아 적당히 압축을 풀자. 프로젝트의 Resources -> drawable 존재하는 Icon.png 파일을 먼저 삭제후 압축푼 경로 아래 Android\drawable 폴더의 Icon.png를 다시 선택해 주면 되는데 솔루션 탐색기 -> Ressources -> drawable 에서 마우스 우측버튼 -> 추가 -> 기존항목을 선택 후 압축 푼 경로의 Android\drawable 아래의 Icon.png 파일을 선택하면 아이콘이 등록된다.
앞에서 다운 받은 파일의 Android\drawable* 폴더들을 프로젝트로 복사하면 되는데 drawable 폴더를 제외한 모든 폴더를 복사 후 프로젝트의 Resources 아래에 붙여넣자.
다음은 Android Manifest안에 아이콘을 등록하면 되는데 솔루션 탐색기의 Properties 더블클릭 -> 왼쪽에서 Android Manifest를 선택 후 나타나는 화면의 Application Icon 메뉴에서 @drawble/Icon을 선택하자.
4. 2.1 Hello Android
(Xamarin.Android Application) Example
탑크리에듀 http://www.topcredu.co.kr/
if (!string.IsNullOrWhiteSpace(phoneNumberText.Text))
callButton.Enabled = true;
else
callButton.Enabled = false;
};
callButton.Click += (object sender, EventArgs e) =>
{
//Make a Call 버튼 클릭시 전화를 건다.
var callDialog = new AlertDialog.Builder(this);
callDialog.SetMessage("Call " + phoneNumberText.Text + "?");
//"Call"을 클릭하는 경우
// 전화걸기 위한 인텐트 생성
callDialog.SetNeutralButton("Call", delegate
{
5. 2.1 Hello Android
(Xamarin.Android Application) Example
탑크리에듀 http://www.topcredu.co.kr/
// 인텐트는 액티비티의 전환이 일어날 때 호출하거나 메시지를 전달하는 매개체
// 암시적 인텐트 : 전환될 곳을 직접 지정하지 않고 액션을 적어서 사용한다.
// 명시적 인텐트 : 전환될 액티비티를 직접 적어서 표현하는 방법을 사용한다.
var callIntent = new Intent(Intent.ActionCall);
callIntent.SetData(Android.Net.Uri.Parse("tel:" + phoneNumberText.Text));
StartActivity(callIntent);
});
//Cancel을 클릭하는 경우
callDialog.SetNegativeButton("Cancel", delegate { });
callDialog.Show();
};
}
}
}
6. 2.1 Hello Android
(Xamarin.Android Application) Example
Application에 전화거는 기능을 활성화 시키자. Android Manifest안에 권한과 관련된 부분을
정의해야 하는데, 솔루션 탐색기에서 Properties를 더블클릭하고 좌측 Android Manifest를
선택 후 하단의 Permission중 “CALL_PHONE” permission을 활성화 하자.
탑크리에듀 http://www.topcredu.co.kr/
7. 2.1 Hello Android
(Xamarin.Android Application) Example
모든 변경사항을 저장(Ctrl+Shift+S)하고 빌드하자.(Build > Rebuild Solution)
MainActivity.cs의 Label은 응용프로그램의 스크린 최상단에 디스플레이되는 텍스트이니 필요
하다면 수정을 하면 된다.
탑크리에듀 http://www.topcredu.co.kr/
[Activity(Label = "Xamarin Android", MainLauncher = true, Icon =
"@drawable/icon")]
public class MainActivity : Activity {
응용프로그램의 아이콘을 설정할 수 있는데
https://developer.xamarin.com/guides/android/getting_started/hello,android/Resour
ces/XamarinAppIconsAndLaunchImages.zip 에서 아이콘 ZIP파일을 다운받아 적당히 압축
을 풀자. 프로젝트의 Resources -> drawable 존재하는 Icon.png 파일을 먼저 삭제후 압축푼
경로 아래 Androiddrawable 폴더의 Icon.png를 다시 선택해 주면 되는데 솔루션 탐색기 ->
Ressources -> drawable 에서 마우스 우측버튼 -> 추가 -> 기존항목을 선택 후 압축 푼 경로
의 Androiddrawable 아래의 Icon.png 파일을 선택하면 아이콘이 등록된다.
9. 2.1 Hello Android
(Xamarin.Android Application) Example
탑크리에듀 http://www.topcredu.co.kr/
앞에서 다운 받은 파일의 Androiddrawable* 폴더들을 프로젝트로 복사하면 되는데
drawable 폴더를 제외한 모든 폴더를 복사 후 프로젝트의 Resources 아래에 붙여넣자.
10. 2.1 Hello Android
(Xamarin.Android Application) Example
탑크리에듀 http://www.topcredu.co.kr/
다음은 Android Manifest안에 아이콘을 등록하면 되는데 솔루션 탐색기의 Properties 더블클릭 -> 왼쪽에서
Android Manifest를 선택 후 나타나는 화면의 Application Icon 메뉴에서 @drawble/Icon을 선택하
자.
11. 2.1 Hello Android
(Xamarin.Android Application) Example
탑크리에듀 http://www.topcredu.co.kr/
이제 에뮬레이터, 또는 안드로이드폰으로 테스트를 해보자.
Properties를 더블클릭 후 좌측 Application 에서 API LEVEL 23(mashimallow)로 설정하고 이뮬레이터를 실행했다.
상단의 실행단추를 눌러 실행하자.
15. 2.1 Hello Android
(Xamarin.Android Application) Example
폰으로 테스트 하기 위해서는 휴대폰을 USB로 연결 후 폰에서 USB 디버깅을 활성화 해야 되는
데 휴대폰 상단 설정을 클릭하고 더보기 -> 개발자옵션 ->USB 디버깅을 체크하자. 또는 갤럭
시 S4이후, 안드로이드4.2 젤리빈 이후의 폰들은 개발자 옵션이 비활성화 되어있으므로 설정 -
> 디바이스 정보 -> 빌드번호 를 7번 클릭하면 “개발자 모드가 실행되었습니다” 라는 메시지가
나오면서 개발자 모드가 활성화 된다. 개발자 모드를 활성화하면 USB 디버깅도 같이 활성화 하
자.
탑크리에듀 http://www.topcredu.co.kr/
[휴대폰 실행화면]