Is it possible to force either Yes/No from any and

2019-09-26 03:29发布

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条回答
走好不送
2楼-- · 2019-09-26 04:07

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.

查看更多
登录 后发表回答