简体   繁体   English

INTENT.ACTION_CALL在后台

[英]INTENT.ACTION_CALL in background

I need to call in background in my app, so when the user click a button, it should start calling in the background, the user will know that he is calling, but he wont see the Dialer, he will see the app, to reproduce sounds while calling. 我需要在我的应用程序中后台调用,因此,当用户单击一个按钮时,它应该开始在后台调用,用户将知道他正在呼叫,但是他不会看到Dialer,而是会看到该应用程序,以便进行复制通话时发出声音。

So basically what i want is make a call without exit of the activity 所以基本上我想要的是拨打电话而不退出活动

I tryed with a service but it doesnt work 我尝试了一项服务,但没有用

 Intent callIntent = new Intent(Intent.ACTION_CALL);
 callIntent.setData(Uri.parse("tel:123456789"));
 startService (callIntent);

Sorry about my english 对不起我的英语

Try this one: 试试这个:

Intent callIntent = new Intent(Intent.ACTION_CALL);
 callIntent.setData(Uri.parse("tel:123456789"));
 startActivity(callIntent);

* Notice the startActivity(callIntent) , instead of startService(callIntent); * 注意startActivity(callIntent) ,而不是startService(callIntent); .

You can also experiment with ACTION_DIAL , instead of ACTION_CALL . 您也可以尝试使用ACTION_DIAL代替ACTION_CALL You'll also need this permission, but place it before the Application tag in the AndroidManifest : 您还需要此权限,但要将其放在AndroidManifest的Application标记之前:

<uses-permission android:name="android.permission.CALL_PHONE" />

Code Behind: 背后的代码:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    call();
}

private void call() {
    try {
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:123456789"));
        startActivity(callIntent);
    } catch (ActivityNotFoundException e) {
        Log.e("sample call in android", "Call failed", e);
    }
}

Manifest.xml 的Manifest.xml
Add.. 加..

<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>

Or, 要么,

<uses-permission android:name="android.permission.CALL_PRIVILEGED"></uses-permission>

EDIT: Well, tasomaniac made a good point about existing current activity which OP also wants. 编辑:好吧, 塔斯马尼亚克对OP也想要的现有当前活动提出了很好的看法

So basically what i want is make a call without exit of the activity . 所以基本上我想要的是拨打电话而不退出活动

But it is impossible to do anything during call states of telephony interface in android.One possible good solution would be PhoneStateListener to see when the call is ended and then resume your current activity.Some very good solutions are described.. 但是在PhoneStateListener的电话接口的通话状态期间不可能做任何事情PhoneStateListener可能是一个好的解决方案,它可以查看通话何时结束并随后恢复当前活动。其中描述了一些非常好的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM