[英]How can I call a number from button press in Android?
我非常喜歡這個,我正在努力讓它發揮作用。
當按下按鈕時,我只想讓撥號器打開並自動輸入指定的號碼。
到目前為止,我已經嘗試了以下內容:
Button btn_call_us = (Button) findViewById(R.id.btn_call_us);
btn_call_us.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:00000000"));
startActivity(callIntent);
}
});
我也嘗試過:
Button btn_call_us = (Button) findViewById(R.id.btn_call_us);
btn_call_us.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String phoneno="00000000";
Intent i=new Intent(Intent.ACTION_CALL,Uri.parse(phoneno));
startActivity(i);
}
});
我已將權限ACTION_CALL添加到清單中。
每當我點擊“呼叫”按鈕時,應用程序強制關閉。
任何幫助將不勝感激。
謝謝!
String number = "12345678";
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" +number));
startActivity(intent);
您需要將此權限添加到清單中。
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
我認為你必須在Manifest中添加<uses-permission android:name="android.permission.CALL_PHONE" />
。
如果您希望使用數字打開撥號器,請使用ACTION_DIAL
Intent i=new Intent(Intent.ACTION_DIAL,Uri.parse("tel:" + phoneno));
您不需要任何許可
確保你已經添加了
<uses-permission android:name="android.permission.CALL_PHONE" />
標記在AndroidManifest.xml文件中的正確級別(在<application ... />
標記之外但在<manifest ... />
標記內):
嘗試這個。
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneno)));
另外,在manifest
文件中添加權限android.permission.CALL_PHONE
。
在清單文件中添加以下內容,它應該可以正常工作 -
<uses-permission android:name="android.permission.CALL_PHONE"/>
在你的Android手機中轉到:“設置” - >“InstalledApp” - >“找到你的應用程序” - >“應用程序權限” - >“這里允許”電話許可“希望它會幫助你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.