2012-12-29 1 views
1

edittext에서 번호를 얻으면 어떻게 전화를합니까? 나는 이것을 시도하지만 효과가 없다. 변수 번호를 Uri.parse()에 전달할 때 문제가 발생합니다. gettext가 void가되어야합니다.전화 걸기 android and edittext 상자에서 번호 받기

public String string; 
public String number; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 


    EditText txtcallnumber; 
    txtcallnumber = (EditText)findViewById(R.id.callnumber); 
    string = txtcallnumber.getText().toString().trim();//There no work call 
     number = "tel:" + string; 

    Button button = (Button) findViewById(R.id.button1); 
    button.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
      call(); 
     } 
     }); 
} 


public void call() { 
try { 
    Intent callIntent = new Intent(Intent.ACTION_CALL); 
    //callIntent.setData(Uri.parse("tel:xxxxxxx")); //This work 
    string = txtcallnumber.getText().toString().trim(); 
     number = "tel:" + string;//There work call 
    callIntent.setData(Uri.parse(number)); 
    startActivity(callIntent); 


} catch (ActivityNotFoundException activityException) { 
    Log.e("helloandroid dialing example", "Call failed"); 
} 

답변

0

당신은 거기에서 onCreate 방법이 의도 ::

number=edittext.getText().trim(); 
no="tel:"+number; 

startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(no))); 
+0

확인 작업을 now.Thanks.But 이유를 작업 할 때 빈 내부에 :

게다가 당신은 입력 아무것도 확인이 있어야한다? – user1909897

+0

@ user1909897 "내부 무효"란 무엇을 의미합니까? –

+0

@ user1909897 길은 절대적 이었지만 ACTION_CALL은 권한이 필요하므로 로그에 보안 오류가 발생했습니다. –

0

를 사용하려고 매니페스트 파일 :

전화 내부
<uses-permission android:name="android.permission.CALL_PHONE"> 

() 메소드 내부에 권한을 추가 할 필요가 필요가 없습니다 :

string = txtcallnumber.getText().toString().trim(); 
number = "tel:" + string; 

원인 onCreate는 디스플레이 설정에 꽤 많이 사용되며 화면이 설정되기 전에 사용자가 입력을하지 않지만 텍스트를 입력 한 후 버튼을 누르면 onCall 메서드에서 wouldd ... 알 수 있습니다.

if(string!=null){ 
    try{try { 
Intent callIntent = new Intent(Intent.ACTION_CALL); 

string = txtcallnumber.getText().toString().trim(); 
    number = "tel:" + string; 
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(number))); 


} catch (ActivityNotFoundException activityException) { 
Log.e("helloandroid dialing example", "Call failed"); 

     }}else{ 
    Log.d("helloandroid dialing example","nothing entered");}