在Android中,CREATE_CALL BII是用于呼叫电话的意图。如果Google助手未提供号码,则可以通过以下代码示例解决:
1.首先,在build.gradle文件中添加以下依赖项:
implementation 'com.google.android.gms:play-services-maps:17.0.0'
2.创建一个类来处理CREATE_CALL意图:
public class CallIntentHandler {
private static final String TAG = CallIntentHandler.class.getSimpleName();
private static final Pattern CALL_PATTERN = Pattern.compile("^(call|dial)\\s*(.*)$");
public static boolean handleIntent(Context context, Intent intent) {
String action = intent.getAction();
String intentType = intent.getType();
String query = "";
if (Intent.ACTION_SEARCH.equals(action)) {
query = intent.getStringExtra(SearchManager.QUERY);
} else if (Intent.ACTION_VIEW.equals(action) && intentType != null) {
query = intent.getData().getLastPathSegment();
}
if (TextUtils.isEmpty(query)) {
return false;
}
Matcher matcher = CALL_PATTERN.matcher(query.trim().toLowerCase());
if (!matcher.matches()) {
return false;
}
String phoneNumber = matcher.group(2);
if (TextUtils.isEmpty(phoneNumber)) {
return false;
}
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber));
context.startActivity(callIntent);
return true;
}
}
3.在您的Activity或Fragment类中覆盖onNewIntent方法,并在其中调用CallIntentHandler:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
boolean handled = CallIntentHandler.handleIntent(this, intent);
if (!handled) {
// Handle other intents here...
}
}
4.最后,在Manifest文件中注册您的Activity,并为其设置以下intent-filter: