Android-电话应用程序,一直专注于传出和放大器;传入phoneCall [英] Android- Telephone app that keeps focus on outgoing & incoming phoneCall

查看:182
本文介绍了Android-电话应用程序,一直专注于传出和放大器;传入phoneCall的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用这个简单的例子来创建拨出硬$ C $#光盘和显示器的手机状态PhoneCall应用程序。

Using this simple example to create a PhoneCall application that dials out a hard coded # and monitors phone state.

HTTP://www.mkyong .COM /安卓/如何对化妆一个电话,通话中的Andr​​oid /

不幸的是,使得电话,我们随时切换到内置-in手机应用程序的实际。

Unfortunately, on making the phone call, we always switch to the actual built -in phone application.

我要避免这种情况,或至少是隐藏拨号键盘按钮。用户不应该必须输入电话号码的选项。

I want to avoid this, or at the very least hide the dialer pad button. The user SHOULD NOT have the option to enter a phone#.

有谁知道的一种方式来实现这一目标?
即,保持在背景的实际内置电话应用
(我需要增加对扬声器和结束通话按钮在主应用程序)

Does anyone know of a way to achieve this? i.e. keep the actual built-in phone application in the background (I would need to add buttons for speaker, and end call in the primary application)

另外,隐藏在刚刚拨号键盘按钮本地,内置手机应用程序?

alternatively, hide just the dial pad button in the native, built-in phone application?

推荐答案

下面是我想出了隐藏主叫应用该呼叫放置不久后的解决方案。我不相信有一种方法,使无需重新编写Android系统是完全透明的。我相信这可以通过当主叫用户应用程序设置检测,而是拨打的postDelayed得到改善()我使用的可能是不可靠的。

Here is a solution I came up with to hide the caller app shortly after the call is placed. I don't believe there is a way to make it totally transparent without re-writing the Android system. I believe this could be improved by detecting when the caller app is set up and dialing instead of the postDelayed() I'm using which could be unreliable.

编辑:我试图使一个接收器监听 NEW_OUTGOING_CALL 来重新启动原来的活动,但它并没有真正改善什么,拨号器应用程序必须运行的时间任意数量,才可以启动它的后台服务。

I tried making a receiver to listen for NEW_OUTGOING_CALL to restart the original Activity, but it doesn't really improve anything, the dialer app must be running for an arbitrary amount of time before it can start it's background service.

编辑:我试图使一个 PhoneStateListener ,对于 CALL_STATE_OFFHOOK 监听并重新启动活动在那里。前拨号应用程序是完全准备进入后台这不工作,要么因为它发生。

I tried making a PhoneStateListener that listens for CALL_STATE_OFFHOOK and re starts the Activity there. This doesn't work either as it happens before the dialing app is fully ready to go into the background.

编辑:你可以看看这个主题:<一href=\"http://stackoverflow.com/questions/2001146/reflection-to-access-advanced-telephony-features\">Reflection访问高级电话功能,但我相信谷歌有自锁定发出呼叫的标准应用程序之外的所有方法。

You can look at this thread: Reflection to access advanced telephony features, but I believe Google has since locked down all methods of placing a call outside the standard app.

此溶液将开始拨号,然后在几秒钟之后切换回原始活性。

This solution will start the dialing, and then switch back to the original Activity after a couple of seconds.

在我的清单我有:

android:launchMode="singleInstance"

在我的活动,所以我没有得到一个新的实例。

on my Activity so I don't get a new instance.

public class MainActivity extends Activity
{
  ....
    public void clickMe(View view)
    {
        startService(new Intent(this, PhoneService.class));
    }
}


public class PhoneService extends Service
{
    @Override
    public int onStartCommand(Intent intent, int flags, int startId)
    {
        Intent call = new Intent(Intent.ACTION_CALL);
        call.setData(Uri.parse("tel:XXXXXXXXX"));
        call.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(call);

        Handler h = new Handler();
        h.postDelayed(new Runnable() {

            @Override
            public void run()
            {
                Intent act = new Intent(PhoneService.this, MainActivity.class);
                act.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(act);
            }

        }, 4000);

        return super.onStartCommand(intent, flags, startId);


    }

    @Override
    public IBinder onBind(Intent arg0)
    {
        // TODO Auto-generated method stub
        return null;
    }

}

我相信它不可能提供一个清洁的解决方案,给出的SDK的限制。

I believe it impossible to provide a cleaner solution, given the constraints of the SDK.

这篇关于Android-电话应用程序,一直专注于传出和放大器;传入phoneCall的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆