I'm trying to make a call when I press a button in android
当我按下android上的一个按钮时,我正在试着打电话
((Button)findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String phno="10digits";
Intent i=new Intent(Intent.ACTION_DIAL,Uri.parse(phno));
startActivity(i);
}
});
But when I run and click on the button it gives me the error
但是当我运行并点击按钮时它会给我错误
ERROR/AndroidRuntime(1021): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=9392438004 }
How can I resolve this problem?
我如何解决这个问题?
13 个解决方案
#1
124
Have you given the permission in the manifest file
你在舱单文件中得到许可了吗
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
and inside your activity
和在你的活动
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
startActivity(callIntent);
Let me know if you find any issue.
如果有什么问题,请告诉我。
#2
12
change your String to String phno="tel:10digits";
and try again.
将字符串改为String phno="tel:10位";并再次尝试。
#3
11
There are two intents to call/start calling: ACTION_CALL and ACTION_DIAL.
调用/开始调用有两个意图:ACTION_CALL和ACTION_DIAL。
ACTION_DIAL
will only open the dialer with the number
filled in, but allows the user to actually call or reject the call
. ACTION_CALL
will immediately call the number and requires an extra permission.
ACTION_DIAL只会用填充的数字打开拨号器,但允许用户实际调用或拒绝调用。ACTION_CALL将立即调用该号码并需要额外的权限。
So make sure you have the permission
所以一定要得到许可
uses-permission android:name="android.permission.CALL_PHONE"
in your AndroidManifest.xml
在你AndroidManifest.xml
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dbm.pkg"
android:versionCode="1"
android:versionName="1.0">
<!-- NOTE! Your uses-permission must be outside the "application" tag
but within the "manifest" tag. -->
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name">
<!-- Insert your other stuff here -->
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>
#4
9
None of the above worked so with a bit of tinkering here's code that did for me
上面的这些都没有起作用,所以只要稍加修改,这里的代码就可以为我所用
Intent i = new Intent(Intent.ACTION_DIAL);
String p = "tel:" + getString(R.string.phone_number);
i.setData(Uri.parse(p));
startActivity(i);
#5
5
I was having a hell of a time with this as well. I didn't realize that beyond the extra permission you need to append "tel:" onto the string that has the number in it. This is what mine looks like after getting it functional. Hope this helps.
我在这方面也过得很愉快。我没有意识到,除了额外的权限之外,你还需要在字符串中添加“tel:”。这就是我的功能。希望这个有帮助。
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_DIAL);
String temp = "tel:" + phone;
intent.setData(Uri.parse(temp));
startActivity(intent);
}
#6
4
add "tel:" along with your number to be dialed in your intent and then start your activity.
添加“电话:”和你的电话号码,然后开始你的活动。
Intent myIntent = new Intent(Intent.ACTION_CALL);
String phNum = "tel:" + "1234567890";
myIntent.setData(Uri.parse(phNum));
startActivity( myIntent ) ;
#7
4
To have the code within one line, try this:
要将代码放在一行中,请尝试以下方法:
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:123456789")));
along with the proper manifest permission:
连同适当的舱单许可:
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
Hope this helps!
希望这可以帮助!
#8
2
For those using AppCompact...Try this
对于那些使用AppCompact…试试这个
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.net.Uri;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button startBtn = (Button) findViewById(R.id.db);
startBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
makeCall();
}
});
}
protected void makeCall() {
EditText num = (EditText)findViewById(R.id.Dail);
String phone = num.getText().toString();
String d = "tel:" + phone ;
Log.i("Make call", "");
Intent phoneIntent = new Intent(Intent.ACTION_CALL);
phoneIntent.setData(Uri.parse(d));
try {
startActivity(phoneIntent);
finish();
Log.i("Finished making a call", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "Call faild, please try again later.", Toast.LENGTH_SHORT).show();
}
}
}
Then add this to your manifest,,,
然后把它添加到你的舱单中,
<uses-permission android:name="android.permission.CALL_PHONE" />
#9
2
check permissions before (for android 6 and above):
检查权限前(android 6及以上):
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) ==
PackageManager.PERMISSION_GRANTED)
{
context.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:09130000000")));
}
#10
1
Also good to check is telephony supported on device
同样值得检查的是设备上支持的电话
private boolean isTelephonyEnabled(){
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
return tm != null && tm.getSimState()==TelephonyManager.SIM_STATE_READY
}
#11
1
I hope, this short code is useful for You,
## Java Code ##
startActivity(new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+txtPhn.getText().toString())));
----------------------------------------------------------------------
Please check Manifest File,(for Uses permission)
## Manifest.xml ##
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dbm.pkg"
android:versionCode="1"
android:versionName="1.0">
<!-- NOTE! Your uses-permission must be outside the "application" tag
but within the "manifest" tag. -->
## uses-permission for Making Call ##
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name">
<!-- Insert your other stuff here -->
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>
#12
0
I've just solved the problem on an Android 4.0.2 device (GN) and the only version working for this device/version was similar to the first 5-starred with CALL_PHONE permission and the answer:
我刚刚在Android 4.0.2设备(GN)上解决了这个问题,这个设备/版本的唯一版本与前一个5星的CALL_PHONE权限相似,答案是:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
startActivity(callIntent);
With any other solution i got the ActivityNotFoundException on this device/version. How about the older versions? Would someone give feedback?
有了其他的解决方案,我在这个设备/版本上得到了ActivityNotFoundException。旧版本呢?有人会给反馈吗?
#13
0
With permission:
许可:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:9875432100"));
if (ActivityCompat.checkSelfPermission(yourActivity.this,android.Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(yourActivity.this,
android.Manifest.permission.CALL_PHONE)) {
} else {
ActivityCompat.requestPermissions(yourActivity.this,
new String[]{android.Manifest.permission.CALL_PHONE},
MY_PERMISSIONS_REQUEST_CALL_PHONE);
}
}
startActivity(callIntent);
#1
124
Have you given the permission in the manifest file
你在舱单文件中得到许可了吗
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
and inside your activity
和在你的活动
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
startActivity(callIntent);
Let me know if you find any issue.
如果有什么问题,请告诉我。
#2
12
change your String to String phno="tel:10digits";
and try again.
将字符串改为String phno="tel:10位";并再次尝试。
#3
11
There are two intents to call/start calling: ACTION_CALL and ACTION_DIAL.
调用/开始调用有两个意图:ACTION_CALL和ACTION_DIAL。
ACTION_DIAL
will only open the dialer with the number
filled in, but allows the user to actually call or reject the call
. ACTION_CALL
will immediately call the number and requires an extra permission.
ACTION_DIAL只会用填充的数字打开拨号器,但允许用户实际调用或拒绝调用。ACTION_CALL将立即调用该号码并需要额外的权限。
So make sure you have the permission
所以一定要得到许可
uses-permission android:name="android.permission.CALL_PHONE"
in your AndroidManifest.xml
在你AndroidManifest.xml
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dbm.pkg"
android:versionCode="1"
android:versionName="1.0">
<!-- NOTE! Your uses-permission must be outside the "application" tag
but within the "manifest" tag. -->
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name">
<!-- Insert your other stuff here -->
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>
#4
9
None of the above worked so with a bit of tinkering here's code that did for me
上面的这些都没有起作用,所以只要稍加修改,这里的代码就可以为我所用
Intent i = new Intent(Intent.ACTION_DIAL);
String p = "tel:" + getString(R.string.phone_number);
i.setData(Uri.parse(p));
startActivity(i);
#5
5
I was having a hell of a time with this as well. I didn't realize that beyond the extra permission you need to append "tel:" onto the string that has the number in it. This is what mine looks like after getting it functional. Hope this helps.
我在这方面也过得很愉快。我没有意识到,除了额外的权限之外,你还需要在字符串中添加“tel:”。这就是我的功能。希望这个有帮助。
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_DIAL);
String temp = "tel:" + phone;
intent.setData(Uri.parse(temp));
startActivity(intent);
}
#6
4
add "tel:" along with your number to be dialed in your intent and then start your activity.
添加“电话:”和你的电话号码,然后开始你的活动。
Intent myIntent = new Intent(Intent.ACTION_CALL);
String phNum = "tel:" + "1234567890";
myIntent.setData(Uri.parse(phNum));
startActivity( myIntent ) ;
#7
4
To have the code within one line, try this:
要将代码放在一行中,请尝试以下方法:
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:123456789")));
along with the proper manifest permission:
连同适当的舱单许可:
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
Hope this helps!
希望这可以帮助!
#8
2
For those using AppCompact...Try this
对于那些使用AppCompact…试试这个
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.net.Uri;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button startBtn = (Button) findViewById(R.id.db);
startBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
makeCall();
}
});
}
protected void makeCall() {
EditText num = (EditText)findViewById(R.id.Dail);
String phone = num.getText().toString();
String d = "tel:" + phone ;
Log.i("Make call", "");
Intent phoneIntent = new Intent(Intent.ACTION_CALL);
phoneIntent.setData(Uri.parse(d));
try {
startActivity(phoneIntent);
finish();
Log.i("Finished making a call", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "Call faild, please try again later.", Toast.LENGTH_SHORT).show();
}
}
}
Then add this to your manifest,,,
然后把它添加到你的舱单中,
<uses-permission android:name="android.permission.CALL_PHONE" />
#9
2
check permissions before (for android 6 and above):
检查权限前(android 6及以上):
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) ==
PackageManager.PERMISSION_GRANTED)
{
context.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:09130000000")));
}
#10
1
Also good to check is telephony supported on device
同样值得检查的是设备上支持的电话
private boolean isTelephonyEnabled(){
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
return tm != null && tm.getSimState()==TelephonyManager.SIM_STATE_READY
}
#11
1
I hope, this short code is useful for You,
## Java Code ##
startActivity(new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+txtPhn.getText().toString())));
----------------------------------------------------------------------
Please check Manifest File,(for Uses permission)
## Manifest.xml ##
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dbm.pkg"
android:versionCode="1"
android:versionName="1.0">
<!-- NOTE! Your uses-permission must be outside the "application" tag
but within the "manifest" tag. -->
## uses-permission for Making Call ##
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name">
<!-- Insert your other stuff here -->
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>
#12
0
I've just solved the problem on an Android 4.0.2 device (GN) and the only version working for this device/version was similar to the first 5-starred with CALL_PHONE permission and the answer:
我刚刚在Android 4.0.2设备(GN)上解决了这个问题,这个设备/版本的唯一版本与前一个5星的CALL_PHONE权限相似,答案是:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
startActivity(callIntent);
With any other solution i got the ActivityNotFoundException on this device/version. How about the older versions? Would someone give feedback?
有了其他的解决方案,我在这个设备/版本上得到了ActivityNotFoundException。旧版本呢?有人会给反馈吗?
#13
0
With permission:
许可:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:9875432100"));
if (ActivityCompat.checkSelfPermission(yourActivity.this,android.Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(yourActivity.this,
android.Manifest.permission.CALL_PHONE)) {
} else {
ActivityCompat.requestPermissions(yourActivity.this,
new String[]{android.Manifest.permission.CALL_PHONE},
MY_PERMISSIONS_REQUEST_CALL_PHONE);
}
}
startActivity(callIntent);