3 回答

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超5個贊
嘗試使用react-native-immediate-phone-call
import?RNImmediatePhoneCall?from?'react-native-immediate-phone-call'; ... RNImmediatePhoneCall.immediatePhoneCall('0123456789'); ...

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超8個贊
我已經(jīng)看到了很多關(guān)于這方面的東西,所以我終于得到了解決方案。所以解決方案是建立一個黑白橋接本機(jī)和java,這樣你就可以調(diào)用java功能來使用此代碼進(jìn)行直接調(diào)用。 String dial = "tel:" + phn_number; reactcontext.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));
首先檢查權(quán)限。如果未授予,請先請求許可,然后撥打號碼。
if (ContextCompat.checkSelfPermission(reactcontext,
Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(reactcontext.getCurrentActivity(),
new String[]{Manifest.permission.CALL_PHONE}, REQUEST_CALL);
} else {
String dial = "tel:" + phn_number;
reactcontext.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));
}
確保您在清單中添加權(quán)限,例如。
<uses-permission android:name="android.permission.CALL_PHONE" />

TA貢獻(xiàn)1735條經(jīng)驗(yàn) 獲得超5個贊
您可以使用react-native-send-intent庫
如果您需要直接使用電話呼叫,那么在 AndroidManifest.xml 文件中請求許可非常重要。您可以添加可選的第二個參數(shù),以修復(fù)默認(rèn)的手機(jī)應(yīng)用程序。
<uses-permission android:name="android.permission.CALL_PHONE" />
如何使用
? ? var SendIntentAndroid = require("react-native-send-intent");
? ? SendIntentAndroid.sendPhoneCall("+1 234567 8900", true);
示例代碼
? ? var SendIntentAndroid = require("react-native-send-intent");
? ? const InitiateCall = async () => {
? ? ? ? const granted = await PermissionsAndroid.request(
? ? ? ? ? ? PermissionsAndroid.PERMISSIONS.CALL_PHONE,
? ? ? ? ? ? {
? ? ? ? ? ? ? ? title: "App Needs Permission",
? ? ? ? ? ? ? ? message:
? ? ? ? ? ? ? ? ? ? `Myapp needs phone call permission to dial direclty `,
? ? ? ? ? ? ? ? buttonNegative: "Disagree",
? ? ? ? ? ? ? ? buttonPositive: "Agree"
? ? ? ? ? ? }
? ? ? ? );
? ? ? ? if (granted === PermissionsAndroid.RESULTS.GRANTED) {
? ? ? ? ? ? SendIntentAndroid.sendPhoneCall("+1 234567 8900", true);
? ? ? ? ? ? console.log("You dialed directly");
? ? ? ? } else {
? ? ? ? ? ? console.log("No permission");
? ? ? ? }
? ? }
?
? ? return (
? ? ? ? <TouchableOpacity onPress={() => InitiateCall ()}>
? ? ? ? ? ? ? ? ? ?<YourComponent/>
? ? ? ? </TouchableOpacity>
? ? )
您可以在 onPress 事件中使用上述函數(shù)
添加回答
舉報