Unknown On 2014년 6월 30일 월요일

전화걸기 소스 

Intent intent = new Intent( Intent.ACTION_CALL );
intent.setData( Uri.parse( "tel:01012345678" ) );
startActivity( intent );


다이얼번호 소스

Intent intent = new Intent( Intent.ACTION_DIAL );
intent.setData( Uri.parse( "tel:01012345678" ) );
startActivity( intent );



sms 보내기소스

Intent intent = new Intent( Intent.ACTION_VIEW );
intent.setData( Uri.parse( "sms:01012345678" ) );
startActivity(intent);



AndroidManifest.xml에 추가 


<uses-permission android:name="android.permission.CALL_PHONE" />

<uses-permission android:name="android.permission.DIAL_PHONE" />
<uses-permission android:name="android.permission.CALL_PRIVILEGED" />

위에소스를 적용한 JAVA 예제소스

public class main extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Button bt1 = (Button) findViewById(R.id.button1);
bt1.setText("바로전화걸기");
Button bt2 = (Button) findViewById(R.id.button2);
bt2.setText("다이얼로표시");

bt1.setOnClickListener(this);
bt2.setOnClickListener(this);

}

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub

switch (arg0.getId()) {

case R.id.button1:

startActivity(new Intent("android.intent.action.CALL",
Uri.parse("tel:010-0000-0000")));
break;

case R.id.button2:

startActivity(new Intent("android.intent.action.DIAL",
Uri.parse("tel:010-0000-0000")));

break;
}

}
}

여기서 R.Id.button 은 레이아웃 xml에서의 button의 id값이다
android:id="+@id/?????" 주면된다 ex) ?????에 button으로 설정해주면된다.
그리고 AndroidManifest.xml에 추가도 중요!! 

One Response so far.

  1. Unknown says:

    Gooooooooooooooooooood~

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Powered by Blogger.