Is it possible to force either Yes/No from any android Dialog?

与世无争的帅哥 提交于 2019-12-13 11:18:39

问题


I have several intent, that eventually asking the user whether "Yes" or "No".

In which, the dialog itself is not from my code. I just executing the Intent.

My question is quite simple.

How to surpress each dialog shown from the intent and Force it to either "yes" / "no" ?

for example this code:

Intent BlueIntent  = new Intent(bluetooth.ACTION_DISCOVERY_STARTED);
        BlueIntent.putExtra(bluetooth.EXTRA_DISCOVERABLE_DURATION, 300);
        startActivity(BlueIntent);

We all know the above code will ask the user (by showing a YES / No dialog) to the user. So how to force the selection programatically either "yes" or "no" for every dialog shown?

any ideas?


回答1:


Answer:

As much as I know this is normally NOT possible to override user input in another activity.

Reason:

You are opening the Bluetooth Settings using the Intent and let the user handle the rest. any app is not supposed to handle/alter the input events of another (Unless it is an accessibility service). So this fails the whole concept of Application security.

In case of AccessibilityServices the user must start them explicitly using the Accessibility Settings which have special services. see docs.

An AccessibilityService can intercept user input and specific events but I am not sure how it can be used to achieve what you want.

[TIP] I think you can open the Bluetooth directly if you have the android.permission.BLUETOOTH_ADMIN permission. by this you can avoid the default dialog generated by the settings.

Hope my answer helps you.



来源:https://stackoverflow.com/questions/24606971/is-it-possible-to-force-either-yes-no-from-any-android-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!