以编程方式接受牛轧糖的呼叫 [英] Programmatically accept call in Nougat

查看:100
本文介绍了以编程方式接受牛轧糖的呼叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从一年开始,我一直在研究IOT产品,并且所附的应用程序运行正常。现在,我无法在更高版本的android中以编程方式接受呼叫。功能对产品非常重要。

From one year, I have been working over IOT product and the application attached was working fine. Now I am not able to accept call programmatically in higher versions of android. Feature is very important to product. Any help is highly appreciated.

在安全补丁更新 2016年11月之前, Runtime.getRunTime.exec( Command )可以很好地以编程方式接受呼叫。

Before security patch update November 2016, Runtime.getRunTime.exec("Command") was working fine to accept call programmatically.

Runtime.getRuntime().exec("input keyevent " +Integer.toString(KeyEvent.KEYCODE_HEADSETHOOK));

如何在Nougat版本的android中使其​​成为可能。

How to make it possible in Nougat version of android.

正在寻找各种黑客手段。

Looking for any sort of hack.

我已经打开了增强功能的线程。

I have opened a thread for the enhancements.

https://code.google.com/ p / android / issues / detail?can = 2& start = 0& num = 100& q =& colspec = ID%20Status%20Priority%20Owner%20Summary%20Stars%20Reporter%20Opened& groupby =& sort =& id = 231938

注意* 如果任何人遇到相同的问题,请请求 Android开发团队进入其中,并提供获取用户运行时许可的条款。遵循上面提到的URL进行请求。

Note* If any one of you is facing same issue, then please request to Android Dev Team to get in it and provide provision to get run-time permission by user. Follow above mention URL to request.

推荐答案

由于我还在从事IOT产品的开发,因此这是我面临的最大问题之一但是经过一番研究之后,我想我已经找到了解决该问题的方法,或者可以说是一个简单的技巧。
我已经在具有多个版本的多个设备中测试了此hack,发现大多数设备都在响应。只有三星设备没有响应,一些华为设备和某些Oppo设备也没有响应。(我还在为这些设备寻找东西)。

As I am also working on IOT product, this was one of the biggest issue I faced but after some Research, I think I have found some solution for this problem, or you can say a simple hack. I have tested this hack in several devices with several versions, and found that most of the devices are responding. Only Samsung devices are not responding, some Huawei devices and some Oppo devices are also not responding.(I am still looking something for these devices too).

我注意到Android提供访问通知的一项功能。您可以使用 NotificationListenerService 读取通知并对其执行一些操作。
它提供了一些覆盖方法:

I noticed that Android provides one feature of Accessing Notifications. You can use NotificationListenerService to read notifications and perform some actions over them. It provides some override methods:

 onNotificationPosted()
    onNotificationRemoved()
    getActiveNotifications()

...等等

此处是一个代码:
创建一个扩展NotificationListenerService的服务

Here is a code: Create a Service that extends NotificationListenerService

 class NLService extends NotificationListenerService {

     @Override
     public void onNotificationPosted(StatusBarNotification sbn) {
       ....
     }

     @Override
     public void onNotificationRemoved(StatusBarNotification sbn) {
       ....
     }

在AndroidMenifest中,将此服务添加为:

In AndroidMenifest, add this service as:

 <service
        android:name=".NLService"
        android:label="@string/app_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
        <intent-filter>
            <action 
android:name="android.service.notification.NotificationListenerService" />
        </intent-filter>
    </service>

这将使您的应用程序读取收到的任何通知。

This will allow your application to read any notification received.

现在,这是主要代码:

在onNotificationPosted(StatusBarNotification sbn)中添加以下代码:

In onNotificationPosted(StatusBarNotification sbn) add this code:

 @Override
    public void onNotificationPosted(StatusBarNotification sbn) {
        try {
            if (sbn.getNotification().actions != null) {
                for (Notification.Action action : sbn.getNotification().actions) 
                  {
                    Log.e(TAG, "" + action.title);
                    if (action.title.toString().equalsIgnoreCase("Answer")) {
                        Log.e(TAG, "" + true);
                        PendingIntent intent = action.actionIntent;

                        try {
                            intent.send();
                        } catch (PendingIntent.CanceledException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
          } catch (Exception e) {
              e.printStackTrace();
          }
     }

就是这样!

全部设置完毕,运行应用程序和设备(三星除外),无论哪个显示来电通知,并带有接听和拒绝/拒绝操作按钮,将允许您接听电话。

All is set, Run the application and the devices except Samsung, whichever shows a notification for Incoming call, with Answer and Reject/Decline Action buttons, will allow you to answer a call.

要打开通知访问设置并允许您的应用程序读取通知,请使用:

To open Notification Access Settings and allowing your application to read notification, use:

 Intent intent = new 
    Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
        startActivity(intent); 

为此只需创建一个POC,让我知道它的工作原理。

Just create a POC for this and let me know about how it works.

如果有帮助,请标记我的答案。

Please mark my answer if this helps.

此外,如果您可以为Samsung Devices提供相同的解决方案,请进行更新。

Also, if you could provide some solution for the same regarding Samsung Devices, please update.

谢谢

这篇关于以编程方式接受牛轧糖的呼叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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