Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d59ea45

Browse files
Move Android code to separate folder
1 parent aecc12e commit d59ea45

17 files changed

+820
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.0
2+
3+
* Extracts the Android platform implementation from the google_api_availability package.

‎google_api_availability_android/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Baseflow
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# google_api_availability_android
2+
3+
[![style: flutter_lints](https://img.shields.io/badge/style-flutter_lints-40c4ff.svg)](https://pub.dev/packages/flutter_lints)
4+
5+
The official Android implementation of the [`google_api_availability`][1] plugin by Baseflow.
6+
7+
## Usage
8+
9+
This plugin is not yet in use, but will become the endorsed Android implementation later, once `google_api_availability` is updated.
10+
More detailed instructions on using the API can be found in the [README.md][3] of the [`google_api_availability`][1] package.
11+
12+
## Issues
13+
14+
Please file any issues, bugs or feature requests as an issue on our [GitHub](https://github.com/Baseflow/flutter-google-api-availability/issues) page. Commercial support is available, you can contact us at <hello@baseflow.com>.
15+
16+
## Want to contribute
17+
18+
If you would like to contribute to the plugin (e.g. by improving the documentation, solving a bug or adding a cool new feature), please carefully review our [contribution guide](../CONTRIBUTING.md) and send us your [pull request](https://github.com/Baseflow/flutter-google-api-availability/pulls).
19+
20+
## Author
21+
22+
This Google API Availability plugin for Flutter is developed by [Baseflow](https://baseflow.com).
23+
24+
[1]: ../google_api_availability
25+
[2]: lib/google_api_availability_platform_interface.dart
26+
[3]: ../README.md
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
analyzer:
4+
exclude:
5+
# Ignore generated files
6+
- '**/*.g.dart'
7+
- 'lib/src/generated/*.dart'
8+
linter:
9+
rules:
10+
- public_member_api_docs
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
group 'com.baseflow.googleapiavailability'
2+
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
repositories {
6+
google()
7+
mavenCentral()
8+
}
9+
10+
dependencies {
11+
classpath 'com.android.tools.build:gradle:4.1.0'
12+
}
13+
}
14+
15+
rootProject.allprojects {
16+
repositories {
17+
google()
18+
mavenCentral()
19+
}
20+
}
21+
22+
apply plugin: 'com.android.library'
23+
24+
android {
25+
compileSdkVersion 31
26+
27+
compileOptions {
28+
sourceCompatibility JavaVersion.VERSION_1_8
29+
targetCompatibility JavaVersion.VERSION_1_8
30+
}
31+
32+
defaultConfig {
33+
minSdkVersion 16
34+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
35+
}
36+
lintOptions {
37+
disable 'InvalidPackage'
38+
}
39+
}
40+
41+
dependencies {
42+
implementation 'com.google.android.gms:play-services-base:18.1.0'
43+
implementation 'androidx.annotation:annotation:1.1.0'
44+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'google_api_availability'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.baseflow.googleapiavailability">
3+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.baseflow.googleapiavailability;
2+
3+
import androidx.annotation.IntDef;
4+
5+
import com.google.android.gms.common.ConnectionResult;
6+
7+
import java.lang.annotation.Retention;
8+
import java.lang.annotation.RetentionPolicy;
9+
10+
final class GoogleApiAvailabilityConstants {
11+
static final String LOG_TAG = "google_api_availability";
12+
13+
static final int REQUEST_GOOGLE_PLAY_SERVICES = 1000;
14+
15+
//GOOGLE_PLAY_SERVICES_AVAILABILITY
16+
static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SUCCESS = 0;
17+
static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_MISSING = 1;
18+
static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_UPDATING = 2;
19+
static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_VERSION_UPDATE_REQUIRED = 3;
20+
static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_DISABLED = 4;
21+
static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_INVALID = 5;
22+
static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_NOT_AVAILABLE_ON_PLATFORM = 6;
23+
static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_UNKNOWN = 7;
24+
25+
26+
@Retention(RetentionPolicy.SOURCE)
27+
@IntDef({
28+
GOOGLE_PLAY_SERVICES_AVAILABILITY_SUCCESS,
29+
GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_MISSING,
30+
GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_UPDATING,
31+
GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_VERSION_UPDATE_REQUIRED,
32+
GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_DISABLED,
33+
GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_INVALID,
34+
GOOGLE_PLAY_SERVICES_AVAILABILITY_NOT_AVAILABLE_ON_PLATFORM,
35+
GOOGLE_PLAY_SERVICES_AVAILABILITY_UNKNOWN,
36+
})
37+
@interface GooglePlayServicesAvailability {
38+
}
39+
40+
@GooglePlayServicesAvailability
41+
static int toPlayServiceAvailability(int connectionResult) {
42+
switch (connectionResult) {
43+
case ConnectionResult.SUCCESS:
44+
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SUCCESS;
45+
case ConnectionResult.SERVICE_MISSING:
46+
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_MISSING;
47+
case ConnectionResult.SERVICE_UPDATING:
48+
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_UPDATING;
49+
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
50+
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_VERSION_UPDATE_REQUIRED;
51+
case ConnectionResult.SERVICE_DISABLED:
52+
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_DISABLED;
53+
case ConnectionResult.SERVICE_INVALID:
54+
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_INVALID;
55+
default:
56+
return GOOGLE_PLAY_SERVICES_AVAILABILITY_UNKNOWN;
57+
}
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
package com.baseflow.googleapiavailability;
2+
3+
import android.app.Activity;
4+
import android.app.Dialog;
5+
import android.app.PendingIntent;
6+
import android.content.Context;
7+
import android.util.Log;
8+
9+
import com.google.android.gms.common.ConnectionResult;
10+
import com.google.android.gms.common.GoogleApiAvailability;
11+
import com.google.android.gms.tasks.Task;
12+
13+
import java.util.List;
14+
15+
public class GoogleApiAvailabilityManager {
16+
17+
GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
18+
19+
@FunctionalInterface
20+
interface SuccessCallback {
21+
void onSuccess(int connectionResult);
22+
}
23+
24+
@FunctionalInterface
25+
interface MakeGooglePlayServicesAvailableCallback {
26+
void onSuccess(Void v);
27+
}
28+
29+
@FunctionalInterface
30+
interface getErrorStringCallback {
31+
void onSuccess(String errorString);
32+
}
33+
34+
@FunctionalInterface
35+
interface isUserResolvableCallback {
36+
void onSuccess(boolean isUserResolvable);
37+
}
38+
39+
@FunctionalInterface
40+
interface showErrorNotificationCallback {
41+
void onSuccess(Void v);
42+
}
43+
44+
@FunctionalInterface
45+
interface showErrorDialogFragmentCallback {
46+
void onSuccess(boolean showErrorDialogFragmentCallback);
47+
}
48+
49+
@FunctionalInterface
50+
interface ErrorCallback {
51+
void onError(String errorCode, String errorDescription);
52+
}
53+
54+
void checkPlayServicesAvailability(Boolean showDialog, Activity activity, Context applicationContext, SuccessCallback successCallback, ErrorCallback errorCallback) {
55+
if (applicationContext == null) {
56+
Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "The `ApplicationContext` cannot be null.");
57+
errorCallback.onError("GoogleApiAvailability.GoogleApiAvailabilityManager", "Android `ApplicationContext` cannot be null.");
58+
return;
59+
}
60+
61+
final int connectionResult = googleApiAvailability
62+
.isGooglePlayServicesAvailable(applicationContext);
63+
64+
if (activity == null) {
65+
if (showDialog != null && showDialog) {
66+
// Only log warning when `showDialog` property was `true`.
67+
Log.w(GoogleApiAvailabilityConstants.LOG_TAG, "Unable to show dialog as `Activity` is not available.");
68+
}
69+
showDialog = false;
70+
}
71+
72+
if (showDialog != null && showDialog) {
73+
googleApiAvailability
74+
.showErrorDialogFragment(activity, connectionResult, GoogleApiAvailabilityConstants.REQUEST_GOOGLE_PLAY_SERVICES);
75+
}
76+
77+
successCallback.onSuccess(GoogleApiAvailabilityConstants.toPlayServiceAvailability(connectionResult));
78+
}
79+
80+
void makeGooglePlayServicesAvailable(Activity activity, MakeGooglePlayServicesAvailableCallback successCallback, ErrorCallback errorCallback) {
81+
if (activity == null) {
82+
Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "Activity cannot be null.");
83+
errorCallback.onError("GoogleApiAvailability.makeGooglePlayServicesAvailable", "Android Activity cannot be null.");
84+
return;
85+
}
86+
87+
googleApiAvailability.makeGooglePlayServicesAvailable(activity)
88+
.addOnFailureListener((Exception e) -> errorCallback.onError("GoogleApiAvailability.makeGooglePlayServicesAvailable", e.getMessage()))
89+
.addOnSuccessListener((Void t) -> successCallback.onSuccess(null));
90+
}
91+
92+
void getErrorString(Context applicationContext, getErrorStringCallback successCallback, ErrorCallback errorCallback) {
93+
if (applicationContext == null) {
94+
Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null.");
95+
errorCallback.onError("GoogleApiAvailability.getErrorString", "Android context cannot be null.");
96+
return;
97+
}
98+
99+
final String errorString = googleApiAvailability.getErrorString(googleApiAvailability.isGooglePlayServicesAvailable(applicationContext));
100+
101+
successCallback.onSuccess(errorString);
102+
}
103+
104+
void isUserResolvable(Context applicationContext, isUserResolvableCallback successCallback, ErrorCallback errorCallback) {
105+
if (applicationContext == null) {
106+
Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null.");
107+
errorCallback.onError("GoogleApiAvailability.isUserResolvable", "Android context cannot be null.");
108+
return;
109+
}
110+
111+
final int connectionResult = googleApiAvailability
112+
.isGooglePlayServicesAvailable(applicationContext);
113+
114+
successCallback.onSuccess(googleApiAvailability.isUserResolvableError(connectionResult));
115+
}
116+
117+
void showErrorNotification(Context applicationContext, showErrorNotificationCallback successCallback, ErrorCallback errorCallback) {
118+
if (applicationContext == null) {
119+
Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null.");
120+
errorCallback.onError("GoogleApiAvailability.showErrorNotification", "Android context cannot be null.");
121+
return;
122+
}
123+
124+
final int connectionResult = googleApiAvailability
125+
.isGooglePlayServicesAvailable(applicationContext);
126+
127+
googleApiAvailability.showErrorNotification(applicationContext, connectionResult);
128+
129+
successCallback.onSuccess(null);
130+
}
131+
132+
void showErrorDialogFragment(Context applicationContext, Activity activity, showErrorDialogFragmentCallback successCallback, ErrorCallback errorCallback) {
133+
if (applicationContext == null) {
134+
Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null.");
135+
errorCallback.onError("GoogleApiAvailability.showErrorDialogFragment", "Android context cannot be null.");
136+
return;
137+
}
138+
139+
final int errorCode = googleApiAvailability
140+
.isGooglePlayServicesAvailable(applicationContext);
141+
142+
if (errorCode != GoogleApiAvailabilityConstants.GOOGLE_PLAY_SERVICES_AVAILABILITY_SUCCESS) {
143+
googleApiAvailability.showErrorDialogFragment(activity, errorCode, GoogleApiAvailabilityConstants.REQUEST_GOOGLE_PLAY_SERVICES);
144+
successCallback.onSuccess(true);
145+
}
146+
147+
successCallback.onSuccess(false);
148+
}
149+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /