我将一个活动号码传递给活动
然后,在这样的活动中,我有一个按钮来调用该号码,这是代码:
callButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(bundle.getString("mobilePhone")));
}
});
出了点问题,因为当我按下按钮时没有任何反应......
我究竟做错了什么?
PD:我正在使用Android 1.5兼容项目...也许电话与1.5不兼容?
你忘了打电话给startActivity。它应该如下所示:
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + bundle.getString("mobilePhone")));
context.startActivity(intent);
意图本身就是描述某事物的对象。它没有做任何事情。
不要忘记向清单添加相关权限:
<uses-permission android:name="android.permission.CALL_PHONE" />
在我的手机上试过这个,它完美无缺。
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:900..." ));
startActivity(intent);
在清单文件中添加此权限。
<uses-permission android:name="android.permission.CALL_PHONE" />
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+198+","+1+","+1));
startActivity(callIntent);
用于多个有序呼叫
这用于DTMF呼叫系统。如果呼叫丢失,那么你应该在数字之间传递更多“,”。
在所选答案中,没有检查棉花糖许可。它不能直接在marshmallow 6.0或以上设备中使用。
我知道我来不及但这个问题投票很多,所以我认为这将有助于其他人。
在棉花糖设备中,我们需要获得运行时间的电话许可...
这是在棉花糖或以上进行呼叫的示例。
看看那里:http://developer.android.com/guide/topics/intents/intents-filters.html
您是否更新了清单文件以获得通话权限?
在这里,我将向您展示如何通过您的活动拨打电话。要拨打电话,您必须在应用中记下此代码。
try {
Intent my_callIntent = new Intent(Intent.ACTION_CALL);
my_callIntent.setData(Uri.parse("tel:"+phn_no));
//here the word 'tel' is important for making a call...
startActivity(my_callIntent);
} catch (ActivityNotFoundException e) {
Toast.makeText(getApplicationContext(), "Error in your phone call"+e.getMessage(), Toast.LENGTH_LONG).show();
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button button = (Button) findViewById(R.id.btn_call);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String mobileNo = "123456789";
String uri = "tel:" + mobileNo.trim();
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(uri));
startActivity(intent);
}
});*
}
如果有人在Kotlin寻找
val uri = "tel:"+800******
val call_customer_service = Intent(Intent.ACTION_CALL)
call_customer_service.setData(Uri.parse(uri))
startActivity(call_customer_service)