简体   繁体   English

Android-Telephony应用程序,专注于来电

[英]Android-Telephony application that keeps focus on incoming calls

I am developing a custom telephony application that is able to receive calls. 我正在开发一个能够接听电话的自定义电话应用程序。 Using this code for handling the incoming call https://code.google.com/p/auto-answer/source/browse/trunk/src/com/everysoft/autoanswer/AutoAnswerIntentService.java 使用此代码处理来电https://code.google.com/p/auto-answer/source/browse/trunk/src/com/everysoft/autoanswer/AutoAnswerIntentService.java

Unfortunately my app loses focus on the incoming call. 不幸的是,我的应用程序失去了对来电的关注。

THIS was a partial solution for outgoing calls Android- Telephone app that keeps focus on outgoing & incoming phoneCall 对于拨打电话Android-电话应用程序而言,这是一个部分解决方案,可以专注于拨出和拨入电话

What about incoming calls? 来电怎么样? How do I keep focus in my custom app? 如何将注意力集中在自定义应用中?

I am guessing this might involve downloading and modifying the source code as simply accessing the SDK gives little control over the built-in phone application. 我猜这可能涉及下载和修改源代码,因为简单地访问SDK几乎无法控制内置电话应用程序。

Since the reference you made about outgoing calls is acceptable, then you can place an activity in front of the incoming call screen shortly after it displays. 由于您对拨出电话的参考是可以接受的,因此您可以在显示后立即在来电屏幕前放置一个活动。 The difficulty in doing this is that the call state will change to "RINGING" and then also "OFFHOOK" but the phone has not displayed the InCallScreen when these are broadcast. 这样做的难点在于呼叫状态将变为“RINGING”然后也“OFFHOOK”,但是当广播时,电话没有显示InCallScreen。

Like the post you referenced, this solution does not actually embed the phone feature into the app (like a webview for web browsing) but rather places an activity in front of the InCallScreen shortly after it displays. 与您引用的帖子一样,此解决方案实际上并未将手机功能嵌入应用程序(如用于Web浏览的Webview),而是在显示后立即将活动放在InCallScreen前面。

For incoming calls, you need to delay the launch of your activity, like in this post: 对于来电,您需要延迟活动的发布,如以下帖子:

Android - Customised New Incoming Call Screen Android - 自定义新的来电屏幕

You can put anything on the screen at the point, the hard part is determining the lag time so that it meets your needs (slow enough so that the InCallScreen has a chance to launch but fast enough to be minimally disruptive). 您可以在屏幕上放置任何内容,困难的部分是确定延迟时间以满足您的需求(足够慢以使InCallScreen有机会启动但速度足以最小程度地破坏)。

Beyond that, even extending AOSP will not help unless you have access to each physical device where this will be used to root them or put a custom build on them. 除此之外,即使扩展AOSP也无济于事,除非您可以访问每个物理设备,这些物理设备将用于根据它们或在其上放置自定义构建。 Access to the PhoneApp features is not accessible to non-system apps (the com.android.phone package). 非系统应用程序(com.android.phone程序包)无法访问PhoneApp功能。

Mention the below broadcast receiver in manifest.xml file. 在manifest.xml文件中提及以下广播接收器。

<receiver android:name="com.example.incomingcall.IncomingCallReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.PHONE_STATE" />
        </intent-filter>
</receiver>

IncomingCallReceiver.java: IncomingCallReceiver.java:

public class IncomingCallReceiver extends BroadcastReceiver{

      public void onReceive(Context context, Intent intent) {
          Bundle extras = intent.getExtras();
          if (extras != null) {
          String state = extras.getString(TelephonyManager.EXTRA_STATE);
          if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
           Thread thread = new Thread(){
            private int sleepTime = 400;

        @Override
        public void run() {
         super.run();
        try {
                int wait_Time = 0;

                while (wait_Time < sleepTime ) {
                    sleep(100);
                    wait_Time += 100;
                }
            }catch (Exception e) {
                Toast.makeText(context,
                        "Error Occured Because:" + e.getMessage(),
                        Toast.LENGTH_SHORT).show();
            }
          context.startActivity(new Intent(context,CustomActivity.class)
                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        }
    };
    thread.run();

     }
   }
 }
}

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

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