以编程方式接受Nougat中的呼叫

And*_*ker 19 android android-security android-7.0-nougat android-7.1-nougat

从一年开始,我一直在研究物联网产品,所附的应用程序工作正常.现在我无法在更高版本的android中以编程方式接受调用.功能对产品非常重要.任何帮助都非常感谢.

2016年11月安全补丁更新之前,Runtime.getRunTime.exec("Command")以编程方式接受呼叫工作正常.

Runtime.getRuntime().exec("input keyevent " +Integer.toString(KeyEvent.KEYCODE_HEADSETHOOK));
Run Code Online (Sandbox Code Playgroud)

如何在Nougat版本的android中实现它.

寻找任何类型的黑客.

我已经为增强功能打开了一个帖子.

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 Dev Team并提供用户获得运行时许可的条款.按照上面提到的URL来请求.

Vis*_*rma 10

由于我也在研究IOT产品,这是我遇到的最大问题之一,但经过一些研究,我认为我找到了解决这个问题的方法,或者你可以说一个简单的黑客.我已经在几个版本的多个设备中测试了这个hack,并发现大多数设备都在响应.只有三星设备没有响应,一些华为设备和一些Oppo设备也没有响应.(我仍然在寻找这些设备的东西).

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

 onNotificationPosted()
    onNotificationRemoved()
    getActiveNotifications()
Run Code Online (Sandbox Code Playgroud)

......等

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

 class NLService extends NotificationListenerService {

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

     @Override
     public void onNotificationRemoved(StatusBarNotification sbn) {
       ....
     }
Run Code Online (Sandbox Code Playgroud)

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

 <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>
Run Code Online (Sandbox Code Playgroud)

这将允许您的应用程序读取收到的任何通知.

现在,这是主要代码:

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

 @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();
          }
     }
Run Code Online (Sandbox Code Playgroud)

而已!

全部设置,运行应用程序和三星以外的设备,无论哪个显示来电通知,使用应答和拒绝/拒绝操作按钮,您都可以接听电话.

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

 Intent intent = new 
    Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
        startActivity(intent); 
Run Code Online (Sandbox Code Playgroud)

只需为此创建一个POC,让我知道它是如何工作的.

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

此外,如果您可以为三星设备提供相同的解决方案,请更新.

谢谢


Sta*_*Kou 1

这是一种黑客行为,您可以使用辅助服务来接听电话。要启用无障碍服务,您必须在“设置”-“无障碍”-“您的服务”中启用您的服务。

首先,将 typeWindowContentChanged 添加到accessibilityEventTypes。

<accessibility-service
     android:accessibilityEventTypes="typeViewClicked|typeViewFocused|typeViewScrolled|typeWindowContentChanged|typeWindowStateChanged"
     android:packageNames="com.example.android.myFirstApp, com.example.android.mySecondApp"
     android:accessibilityFeedbackType="feedbackSpoken"
     android:notificationTimeout="100"
     android:settingsActivity="com.example.android.apis.accessibility.TestBackActivity"
     android:canRetrieveWindowContent="true"
/>
Run Code Online (Sandbox Code Playgroud)

并用事件或“显示的文本”或“内容描述”做一些事情。

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {

    // Do something with Click or Focused event
    final int eventType = event.getEventType();
    String eventText = null;
    switch(eventType) {
        case AccessibilityEvent.TYPE_VIEW_CLICKED:
            eventText = "Focused: ";
            break;
        case AccessibilityEvent.TYPE_VIEW_FOCUSED:
            eventText = "Focused: ";
            break;
    }
    eventText = eventText + event.getContentDescription();


    // Traverse all items in screen. 
    // Do something with text.

    AccessibilityNodeInfo info = getRootInActiveWindow();

    int index;
    int count = info.getChildCount();
    AccessibilityNodeInfo child;

    for (index = 0; index < count; index++) {
        child = info.getChild(index);
        if (child.getText() != null)
            Log.d(TAG, "text: " + child.getText().toString() + " " + child.getContentDescription());

        // perform Click
        //if (child.isClickable());
            //child.performAction(AccessibilityNodeInfo.ACTION_CLICK);
    }
}
Run Code Online (Sandbox Code Playgroud)

是的,我知道这不是解决您问题的优雅方法。这是一种黑客行为。