Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(firebase_messaging, android)!: android 13 notifications permissi…
…on request (#9348) `android.permission.POST_NOTIFICATIONS` has been added to the FirebaseMessaging "AndroidManifest.xml" for requesting notification permission.
- Loading branch information
1 parent
bb9b3b2
commit 43b3b06
Showing
9 changed files
with
153 additions
and
19 deletions.
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