2012-11-10 24 views
0

我不知道是否有可能,但在我的应用程序中,我得到了一个显示电话号码的活动(从网上检索)。 我可以将此号码发送到android的主手机应用程序吗?例如调用它还是保存它?在应用程序外部使用电话号码?

+0

“例如调用它还是保存它?”你可以做到这两点,你有什么尝试? – Sam

+0

我什么都没试,因为我不知道在哪里看。但我在这里找到答案: http://developer.android.com/reference/android/content/Intent.html http://developer.android.com/training/basics/intents/sending.html – Jordane

+0

好吧,这个可能会有所帮助:[按一下按钮点击一个号码](http://stackoverflow.com/q/5230912/1267661),这也是:[添加号码联系](http://stackoverflow.com/q/2206236/1267661 ) – Sam

回答

1

您可以创建一个tel:...Uri,其中...是由你的电话号码代替,然后使用UriACTION_DIALACTION_CALL。例如:

package com.commonsware.android.dialer; 

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

public class DialerDemo extends Activity { 
    @Override 
    public void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
    setContentView(R.layout.main); 
    } 

    public void dial(View v) { 
    EditText number=(EditText)findViewById(R.id.number); 
    String toDial="tel:"+number.getText().toString(); 

    startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(toDial))); 
    } 
} 

上面显示的代码是从this sample project

相关问题