-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat(firebase_messaging, android)!: android 13 notifications permission request #9348
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ed2bf54
feat(messaging, android): pt.1 android 13 notifications: config.
russellwheatley ce4dfaf
feat(messaging, android): pt.2 android 13 notifications: permissions …
russellwheatley fea4270
feat(messaging, android): pt.3 move manifest permission
russellwheatley 4bc4121
chore(messaging, android): clean up
russellwheatley f3a4b3a
fix(messaging): messaging build.gradle ought to target sdk 33
russellwheatley 0a0078f
tests: auto-generated FlutterMultiDexApplication.java update
russellwheatley 8cfd532
format
russellwheatley c72bc56
chore(messaging, android): check POST_NOTIFICATIONS for android 13 pe…
russellwheatley 6509968
chore(messaging, android): PR feedback for android 13 notifications
russellwheatley 6edb65a
Merge branch 'master' into @russell/android-13
russellwheatley 0fd8de4
chore(messaging, android): rm throw and implement API level 33
russellwheatley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...src/main/java/io/flutter/plugins/firebase/messaging/FlutterFirebasePermissionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package io.flutter.plugins.firebase.messaging; | ||
|
||
import android.Manifest; | ||
import android.app.Activity; | ||
import android.content.pm.PackageManager; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.annotation.RequiresApi; | ||
import androidx.core.app.ActivityCompat; | ||
import io.flutter.plugin.common.PluginRegistry; | ||
import java.util.ArrayList; | ||
|
||
class FlutterFirebasePermissionManager implements PluginRegistry.RequestPermissionsResultListener { | ||
|
||
private final int permissionCode = 24; | ||
@Nullable private RequestPermissionsSuccessCallback successCallback; | ||
private boolean requestInProgress = false; | ||
|
||
@FunctionalInterface | ||
interface RequestPermissionsSuccessCallback { | ||
void onSuccess(int results); | ||
} | ||
|
||
@Override | ||
public boolean onRequestPermissionsResult( | ||
int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | ||
requestInProgress = false; | ||
if (requestCode != permissionCode) { | ||
return false; | ||
} | ||
|
||
int grantResult = grantResults[0]; | ||
assert this.successCallback != null; | ||
this.successCallback.onSuccess(grantResult == PackageManager.PERMISSION_GRANTED ? 1 : 0); | ||
return true; | ||
} | ||
|
||
@RequiresApi(api = 33) | ||
public void requestPermissions( | ||
Activity activity, | ||
RequestPermissionsSuccessCallback successCallback, | ||
ErrorCallback errorCallback) { | ||
if (requestInProgress) { | ||
errorCallback.onError( | ||
"A request for permissions is already running, please wait for it to finish before doing another request."); | ||
return; | ||
} | ||
|
||
if (activity == null) { | ||
errorCallback.onError("Unable to detect current Android Activity."); | ||
return; | ||
} | ||
|
||
this.successCallback = successCallback; | ||
final ArrayList<String> permissions = new ArrayList<String>(); | ||
permissions.add(Manifest.permission.POST_NOTIFICATIONS); | ||
final String[] requestNotificationPermission = permissions.toArray(new String[0]); | ||
|
||
if (!requestInProgress) { | ||
ActivityCompat.requestPermissions(activity, requestNotificationPermission, permissionCode); | ||
requestInProgress = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 9 additions & 2 deletions
11
tests/android/app/src/main/java/io/flutter/app/FlutterMultiDexApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably mention this in the changelog for this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can manually edit this when doing the next release I guess 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can change the squash message when merging from GitHub directly