aas*_*ima 7 android phone-call android-intent
这是我的代码:
public String a_number;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_make_the_call);
//
callButton = (ImageButton)findViewById(R.id.call_button);
aCall = (TextView)findViewById(R.id.number_a);
a_number = aCall.getText().toString();
}
public void makeCallFunction(View view) {
String temp = "";
temp = "tel:"+a_number;
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse(temp));
startActivity(callIntent);
}
Run Code Online (Sandbox Code Playgroud)
我的XML文件包含:
<ImageButton
android:id="@+id/call_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:src="@drawable/dial"
android:onClick="makeCallFunction"/>
Run Code Online (Sandbox Code Playgroud)
我在清单文件中添加了以下内容:
<uses-permission android:name="android.permission.CALL_PHONE"/>
Run Code Online (Sandbox Code Playgroud)
我搜索了我最好的答案,但没有找到任何帮助..
编辑:
当我直接给出一个值时,就会立即调用该调用.例如:
callIntent.setData(Uri.parse("tel:9876543210"));
Run Code Online (Sandbox Code Playgroud)
但是当我从文本视图中读取数字并尝试使用该号码拨打电话时,问题仍然存在.
有人可以帮我吗?提前致谢
如果有一些替代方法来实现调用,那也是有帮助的.
在模拟器或调试设备上禁用 SIP Internet 呼叫和 VoIP。这是三星 Galaxy S4 的步骤:
转到设置 > 通话 > 禁用互联网通话(底部)
我不知道你做错了什么,但请自己看看一个有效的示例: MakeTheCallActivity.java
package com.example.makethecall;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MakeTheCallActivity extends ActionBarActivity {
private EditText mEditText;
private Button mButton;
private final String TAG = "MakeTheCallActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_make_the_call);
mButton = (Button)findViewById(R.id.call_button);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mEditText = (EditText)findViewById(R.id.phone_number);
String phoneNumber = mEditText.getText().toString();
Log.d(TAG, phoneNumber);
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber));
startActivity(intent);
}
});
}
Run Code Online (Sandbox Code Playgroud)
}
Activity_make_the_call.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".MakeTheCallActivity"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/phone_number" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="call"
android:id="@+id/call_button" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sauravsamamt.makethecall" >
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MakeTheCallActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
您可以看到我没有使用硬编码的数字。确保您输入有效的号码。就是这样。