2014-01-06 42 views
0

我通过editText从用户获取数字,并设置为TextView成功。我如何实现呼叫意向:我的电话意图错误实施?

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.template); 

final TextView crdMobile = (TextView) findViewById(R.id.crdMobile); 
crdMobile.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 

      Intent callIntent = new Intent(Intent.ACTION_CALL); 
      callIntent.setData(Uri.parse("tel:+"+crdMobile.getText().toString().trim())); 
      //callIntent.setData(Uri.parse(crdMobile.getText().toString().trim())); 
      startActivity(callIntent); 

     } 
    }); 

当我点击crdMobile,设备上出现正常的通话界面。但没有呼叫正在完成。几秒钟后,通话结束,不拨号。你能帮我怎么改善或纠正吗?谢谢。

回答

3

要使用ACTION_CALL你需要持有相关权限:

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

我建议切换到ACTION_DIAL代替反正,因为它不需要任何许可,将不排除对功能没有电话类设备的应用平板电脑

+0

使用ACTION_DIAL要求用户再按一次点击,但我认为它很有用。谢谢。 – Umitk