android.provider.Settings.ACTION_BLUETOOTH_SETTINGS crashes on Samsung

我的未来我决定 提交于 2019-12-11 03:57:07

问题


Anybody have any idea why

Intent pairIntent = new Intent(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
startActivityForResult(pairIntent, 0);

Crashes on all Samsung devices, but works fine on emulator, HTC, Sony, LG etc.

EDITED -----------------------------------

Turns out Samsung also requires BLUETOOTH_ADMIN in the manifest

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

回答1:


If you have an app in production, you need to have something that will allow you to get crash logs. That could be the default stuff that you get from shipping through the Play Store, or an open source solution like ACRA, or any number of service providers.

With regards to your crash, there is no guarantee that this activity is available. Quoting the documentation:

In some cases, a matching Activity may not exist, so ensure you safeguard against this.

The "safeguard" could be wrapping your startActivity() call in an exception handler, watching for ActivityNotFoundException.

Also, please note that you use startActivity(), not startActivityForResult(), with this Intent action. Again, quoting the documentation:

Output: Nothing.

This means that there is no result, and using startActivityForResult() is a waste of time.



来源:https://stackoverflow.com/questions/30006488/android-provider-settings-action-bluetooth-settings-crashes-on-samsung

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