|
1 | 1 | package com.baseflow.googleapiavailability;
|
2 | 2 |
|
3 | 3 | import android.app.Activity;
|
| 4 | +import android.content.Context; |
4 | 5 |
|
5 | 6 | import com.google.android.gms.common.ConnectionResult;
|
6 | 7 | import com.google.android.gms.common.GoogleApiAvailability;
|
@@ -47,24 +48,28 @@ public class GoogleApiAvailabilityPlugin implements MethodCallHandler {
|
47 | 48 |
|
48 | 49 | public static void registerWith(Registrar registrar) {
|
49 | 50 | final MethodChannel channel = new MethodChannel(registrar.messenger(), "flutter.baseflow.com/google_api_availability/methods");
|
50 |
| - channel.setMethodCallHandler(new GoogleApiAvailabilityPlugin(registrar.activity())); |
| 51 | + channel.setMethodCallHandler(new GoogleApiAvailabilityPlugin(registrar.context())); |
51 | 52 | }
|
52 | 53 |
|
53 |
| - private final Activity activity; |
| 54 | + private final Context context; |
54 | 55 |
|
55 |
| - private GoogleApiAvailabilityPlugin(Activity activity) { |
56 |
| - this.activity = activity; |
| 56 | + private GoogleApiAvailabilityPlugin(Context context) { |
| 57 | + this.context = context; |
57 | 58 | }
|
58 | 59 |
|
59 | 60 | @Override
|
60 | 61 | public void onMethodCall(MethodCall call, Result result) {
|
61 | 62 | if (call.method.equals("checkPlayServicesAvailability")) {
|
62 | 63 | final Boolean showDialog = call.argument("showDialog");
|
63 | 64 | GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
|
64 |
| - final int connectionResult = googleApiAvailability.isGooglePlayServicesAvailable(activity); |
| 65 | + final int connectionResult = googleApiAvailability.isGooglePlayServicesAvailable(context); |
65 | 66 |
|
66 |
| - if (showDialog != null && showDialog) { |
67 |
| - googleApiAvailability.showErrorDialogFragment(activity, connectionResult, REQUEST_GOOGLE_PLAY_SERVICES); |
| 67 | + |
| 68 | + if (context instanceof Activity) { |
| 69 | + Activity activity = (Activity) context; |
| 70 | + if (showDialog != null && showDialog) { |
| 71 | + googleApiAvailability.showErrorDialogFragment(activity, connectionResult, REQUEST_GOOGLE_PLAY_SERVICES); |
| 72 | + } |
68 | 73 | }
|
69 | 74 |
|
70 | 75 | final int availability = toPlayServiceAvailability(connectionResult);
|
|
0 commit comments