Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing to send broadcast intent on Android 8+ #365

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ishihatta
Copy link

This fixes that some Badger classes (include DefaultBadger) failing to broadcast Intent on Android 8+ devices.
The cause of this issue is that BroadcastHelper.sendIntentExplicitly() broadcasts implicit intents instead of explicit intents.

The original code uses ResolveInfo#resolvePackageName as the package name for the target home app.

    actualIntent.setPackage(info.resolvePackageName);

However, ResolveInfo#resolvePackageName does not mean the package name of the target app and is almost always null.
https://developer.android.com/reference/android/content/pm/ResolveInfo#resolvePackageName
As a result, the sent intent becomes an implicit intent because package name is not set. And on Android 8 and later, broadcasting implicit intents is prohibited.
https://developer.android.com/guide/components/broadcasts#android_80

My solution is to get the package name from ActivityInfo#packageName.
I have confirmed that DefaultBadger works fine on an Android 9 device with this fix.

@HolimaX
Copy link

HolimaX commented Dec 7, 2021

Any chance to get this tested via CircleCI and merged in?

@HolimaX
Copy link

HolimaX commented Feb 6, 2022

@leolin310148 , you here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants