2013-07-19 3 views
0

통화 버튼을 추가하려고합니다. 어떤 것이 button14일까요? 다른 모든 단추는 문자열이 링크로 들어있는 WebActivity 파일을 엽니 다.Android 앱에 통화 버튼 추가

Android에서 프로그래밍하기가 정말 쉽습니다. 나는 누군가가 내가 처음부터 앱을 만드는 것을 도와 주었지만 그는 마을을 벗어나서 이것을 끝내야한다. 어떤 도움이 좋을지 !! 여기

package com.myapp.programname; 

import com.myapp.programname.R; 

import android.net.Uri; 
import android.os.Bundle; 
import android.app.Activity; 
import android.content.Intent; 
import android.view.Menu; 
import android.view.View; 

public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

    public void onButton(View view) { 

     int index = -1; 
     int id = view.getId(); 

     if (id == R.id.button1) { 

      index = 0; 
     } 
     else if (id == R.id.button2) { 

      index = 1; 
     } 
     else if (id == R.id.button3) { 

      index = 2; 
     } 
     else if (id == R.id.button4) { 

      index = 3; 
     } 
     else if (id == R.id.button5) { 

      index = 4; 
     } 
     else if (id == R.id.button6) { 

      index = 5; 
     } 
     else if (id == R.id.button7) { 

      index = 6; 
     } 
     else if (id == R.id.button8) { 

      index = 7; 
     } 
     else if (id == R.id.button9) { 

      index = 8; 
     } 
     else if (id == R.id.button10) { 

      index = 9; 
     } 
     else if (id == R.id.button11) { 

      index = 10; 
     } 
     else if (id == R.id.button12) { 

      index = 11; 
     } 
     else if (id == R.id.button13) { 

      index = 12; 
     } 
     else if (id == R.id.button14) { 

      Intent callIntent = new Intent(Intent.ACTION_CALL); 
      callIntent.setData(Uri.parse("tel:123456789")); 
      startActivity(callIntent); 
     } 

     else { 

      index = 0; 
     } 

     Intent intent = new Intent(this, WebActivity.class); 
     intent.putExtra("link", index); 
     this.startActivity(intent); 
    } 
} 

는 ... 또한

package com.myapp.programname; 

import com.myapp.programname.R; 

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.webkit.WebSettings; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 

public class WebActivity extends Activity { 

    private class MyWebViewClient extends WebViewClient{ 

     @Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) { 

      return false; 
     } 
    } 

    String links[] = {"http://somesite.com", 
      "http://somesite.com", 
      "http://somesite.com", 
      "http://somesite.com", 
      "http://somesite.com", 
      "http://somesite.com", 
      "http://somesite.com", 
      "http://somesite.com", 
      "http://somesite.com, 
      "http://somesite.com", 
      "http://somesite.com", 
      "http://somesite.com", 
      "http://somesite.com"}; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_web); 

     int index = getIntent().getIntExtra("link", 0); 
     WebView myWebView = (WebView) findViewById(R.id.webview); 
     myWebView.getSettings().setJavaScriptEnabled(true); 
     myWebView.getSettings().setLoadWithOverviewMode(true); 
     myWebView.getSettings().setUseWideViewPort(true); 
     myWebView.getSettings().setBuiltInZoomControls(true); 
     myWebView.getSettings().setPluginState(WebSettings.PluginState.ON); 
     myWebView.setWebViewClient(new MyWebViewClient()); 
     myWebView.loadUrl(links[index]); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.web, menu); 
     return true; 
    } 

} 
+0

기본 내장 Android "통화 응용 프로그램"또는 사용자가 원하는 모든 것을 사용할 수 있습니다. 이렇게하려면 암시적인 의도를 사용하고 결국 호출 할 번호와 같은 추가 정보를 번들에 넣습니다. –

답변

2

당신은 전화에 대한 Intent을 준비하고 이런 식으로 시작할 수 있습니다

String phoneNumber = "555-555-5555"; 
Intent callintent = new Intent(Intent.ACTION_CALL); 
callIntent.setData(Uri.parse("tel:" + phoneNumber)); 
startActivity(callIntent); 

WebActivity 코드입니다 그리고 잊지 마세요 AndroidManifest.xml 파일에이 권한을 포함하십시오 ...

이것으로부터의 참조 question.

+0

위의 코드를 추가하면 걸기가 열리고 전화가 걸리지 만 애플리케이션 강제 종료 오류가 발생합니다. – Jim

+0

다른 항목으로 들어갑니다. 버튼이 맞으면? – Jim

+0

stacktrace 오류를 게시 할 수 있습니까? – Brian