You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

小米Redmi 4手机Intent.ACTION_CALL拨打电话功能失效求助

解决Redmi 4双卡机型上ACTION_CALL直接通话的异常问题

Hey there, let's work through the fixes for the issue you're hitting on the Redmi 4 dual SIM device—where tapping your contact number layout shows a blank screen then bounces back to the root view, even though ACTION_DIAL works perfectly and you've added the CALL_PHONE permission.

1. 先排查动态权限申请(最可能的核心原因)

Even though you've declared <uses-permission android:name="android.permission.CALL_PHONE" /> in your manifest, Android 6.0 (API 23)+ requires dangerous permissions to be requested at runtime, and CALL_PHONE falls into this category. If your app targets API 23+, missing this step will silently block the call intent, leading to the weird blank screen behavior.

Here's how to update your code to handle this:

// Add permission check at the start of your onClick listener
if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.CALL_PHONE}, 101);
    return;
}

// Proceed with call logic only if permission is granted
Intent callIntent = new Intent(Intent.ACTION_CALL);
String contactNumber = "";
try {
    contactNumber = (String) mContactJSONObj.get(Constants.CONTACT_TEL);
    // Sanitize number to remove spaces, hyphens or other non-digit characters
    contactNumber = contactNumber.replaceAll("[^0-9+]", "");
} catch (JSONException e) {
    Log.v(LOG_TAG,"Error fetching contact number: " + e.getMessage());
}
Log.v(LOG_TAG,"Contact number is: "+contactNumber);
callIntent.setData(Uri.parse("tel:" + contactNumber));

// Add try-catch to handle unexpected intent resolution failures
try {
    startActivity(callIntent);
} catch (ActivityNotFoundException e) {
    Log.e(LOG_TAG, "Failed to start call activity: " + e.getMessage());
    Toast.makeText(getActivity(), "Could not initiate call. Check device settings.", Toast.LENGTH_SHORT).show();
}

Also, add the permission request callback to handle user approval/denial:

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == 101) {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            // Re-initiate call after permission is granted
            initiateCall(); // Extract your call logic into a reusable method for this scenario
        } else {
            Toast.makeText(getActivity(), "Call permission is required for direct dialing", Toast.LENGTH_SHORT).show();
        }
    }
}

// Helper method to reuse call logic
private void initiateCall() {
    Intent callIntent = new Intent(Intent.ACTION_CALL);
    String contactNumber = "";
    try {
        contactNumber = (String) mContactJSONObj.get(Constants.CONTACT_TEL);
        contactNumber = contactNumber.replaceAll("[^0-9+]", "");
    } catch (JSONException e) {
        Log.v(LOG_TAG,"Error fetching contact number: " + e.getMessage());
    }
    callIntent.setData(Uri.parse("tel:" + contactNumber));
    try {
        startActivity(callIntent);
    } catch (ActivityNotFoundException e) {
        Log.e(LOG_TAG, "Failed to start call activity: " + e.getMessage());
        Toast.makeText(getActivity(), "Could not initiate call. Check device settings.", Toast.LENGTH_SHORT).show();
    }
}

2. 适配双卡机型的特殊处理

Dual SIM devices (especially Xiaomi's) often require extra intent parameters to specify which SIM card to use for the call. Without this, the system might fail to resolve the intent correctly, causing the blank screen issue.

Add this code right before starting the intent to specify the SIM card:

PhoneAccountManager phoneAccountManager = PhoneAccountManager.get(getActivity());
List<PhoneAccount> phoneAccounts = phoneAccountManager.getPhoneAccounts();
if (!phoneAccounts.isEmpty()) {
    // Use the first SIM card (you can let users choose if needed)
    PhoneAccount firstSim = phoneAccounts.get(0);
    callIntent.putExtra("android.intent.extra.PHONE_ACCOUNT_HANDLE", firstSim.getAccountHandle());
}

This uses the standard Android API for dual SIM handling, which should work for Redmi devices.

3. 再次确认号码格式正确性

Even if your log shows the number is correct, hidden characters (like spaces, hyphens, or parentheses) can break the tel: URI. The sanitization step we added earlier (contactNumber.replaceAll("[^0-9+]", "")) ensures only valid digits and the "+" sign for international numbers are kept.

测试小建议

  • Test the app on a single SIM device first to confirm if the issue is dual-SIM-specific
  • Double-check that CALL_PHONE permission is enabled in your app's settings on the Redmi 4
  • Try hardcoding a simple number (e.g., "1234567890") directly in the intent to rule out number formatting issues

内容的提问来源于stack exchange,提问作者Ndheti

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:44:15