Skip to content

Software Development at Program Tom LTD

Place for coding, programming, development and software in general.

Menu
  • Blog
  • PDF Booklets
  • Dev Utils & Content
  • Java Spring Boot Or Web Apps
  • English
    • български
    • English
    • Español
    • Português
    • हिन्दी
    • Русский
    • Deutsch
    • Français
    • Italiano
    • العربية
  • About Us
  • Flutter Apps
Menu
What Services are included in Google Play lib?

What Services are included in Google Play lib?

Posted on October 25, 2024 by Toma Velev

Google plugs into the Android Platform for their App Store – their own Play Services lib that is closed source, propietery, obfuscated and required for any meaningful app.

1. Google Sign-In

Provides authentication services that allow users to sign in using their Google account.

**GoogleSignInActivity.java**
```java
import android.app.Activity;
import android.os.Bundle;
import com.google.android.gms.auth.GoogleSignIn;
import com.google.android.gms.auth.GoogleSignInClient;
import com.google.android.gms.auth.GoogleSignInOptions;

public class GoogleSignInActivity extends Activity {

    private static final String TAG = "GoogleSignInActivity";
    private GoogleSignInClient mGoogleSignInClient;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Create a Google Sign-In client
        GoogleSignInOptions options = new GoogleSignInOptions.Builder(GoogleSignInOptions.builder())
               .requestId("id")
               .requestEmail(true)
               .build();

        mGoogleSignInClient = GoogleSignIn.getClient(this, options);

        // Start the sign-in flow
        Intent intent = mGoogleSignInClient.getSignInIntent();
        startActivityForResult(intent, 1);
    }

    @Override
    protected void onActivityResult(int requestCode, int responseCode, Intent responseIntent) {
        super.onActivityResult(requestCode, responseCode, responseIntent);

        if (requestCode == 1) {
            // Handle the sign-in result
            GoogleSignInAccount account = mGoogleSignInClient.getSignedInAccount();
            if (account!= null) {
                // Account is signed in
                System.out.println("Signed in: " + account.getDisplayName());
            } else {
                // Account is not signed in
                System.out.println("Not signed in");
            }
        }
    }
}

2. Google Maps and Location Services

This includes:

  • Maps SDK, which adds maps and map-based interactions to apps.
  • Fused Location Provider, offering a more efficient way to obtain device location data (using GPS, Wi-Fi, and cellular networks).
  • Geofencing API, which lets developers create virtual geographic boundaries that trigger events when the user enters or leaves specific areas.
  • Activity Recognition API, which recognizes physical activities like walking, running, or biking.
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class GoogleMapsActivity extends AppCompatActivity implements OnMapReadyCallback {

    private GoogleMap mMap;
    private LocationManager locationManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_google_maps);

        Button button = findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                updateLocation();
            }
        });

        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, new LocationListener() {
                @Override
                public void onLocationChanged(Location location) {
                    updateMap(location);
                }

                @Override
                public void onStatusChanged(String status, int accuracy) {
                    // Do nothing
                }

                @Override
                public void onEnabled(boolean enabled) {
                    // Do nothing
                }
            });
        }

        mMap = ((GoogleMap) findViewById(R.id.map)).getMap();
        mMap.setOnMapReadyCallback(this);
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap.addMarker(new MarkerOptions().position(new LatLng(37.7749, -122.4194)).title("San Francisco"));
    }

    private void updateMap(Location location) {
        if (location!= null) {
            LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
            mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
        }
    }

    private void updateLocation() {
        Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        if (location!= null) {
            updateMap(location);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        locationManager.removeUpdates(this);
    }
}

 

<com.google.android.gms.maps.MapView
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Update Location" />

3. Firebase Integration

Integrates services like Analytics, Crashlytics, Cloud Messaging (for push notifications), Remote Config, and Firestore via Google Play Services.

dependencies {
    implementation 'com.google.firebase:firebase-core:17.3.0'
    implementation 'com.google.firebase:firebase-messaging:22.1.0'
    implementation 'com.google.android.gms:play-services-crashlytics:22.1.0'
    implementation 'com.google.android.gms:play-services-analytics:22.1.0'
}
import com.google.firebase.messaging.FirebaseMessaging;

public class FcmHelper {
    private static FirebaseMessaging mFirebaseMessaging;

    public static void init() {
        mFirebaseMessaging = FirebaseMessaging.getInstance(app);
    }

    public static void registerToken(String token) {
        mFirebaseMessaging.subscribeToTopic(token);
    }

    public static void sendNotification(String token, String message) {
        mFirebaseMessaging.send(message);
    }
}
public class MainActivity extends AppCompatActivity {
    private AnalyticsHelper analyticsHelper;
    private CrashlyticsHelper crashlyticsHelper;
    private FcmHelper fcmHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        analyticsHelper = new AnalyticsHelper();
        crashlyticsHelper = new CrashlyticsHelper();
        fcmHelper = new FcmHelper();

        // Initialize Firebase
        analyticsHelper.init();
        crashlyticsHelper.init();
        fcmHelper.init();

        // Log an event
        analyticsHelper.logEvent("LAUNCH");

        // Log a screen name
        analyticsHelper.logScreenName("MainActivity");

        // Report an exception
        crashlyticsHelper.reportException(new Exception("Test exception"));

        // Register for FCM tokens
        fcmHelper.registerToken("your_fcm_token");

        // Send a notification
        fcmHelper.sendNotification("your_fcm_token", "Hello, world!");
    }
}

4. Google Play Billing

This service provides in-app purchasing functionality, allowing users to make payments within apps through Google Play.

In your build.gradle file, add the following lines:

dependencies {
    implementation 'com.android.billingclient:billing:4.3.0'
}

Initialize the BillingClient

In your MainActivity or any other activity, initialize the BillingClient:

import com.android.billingclient.api.BillingClient;
import com.android.billingclient.api.BillingClientSetupCallback;

public class MainActivity extends AppCompatActivity {
    private BillingClient mBillingClient;
    private String mStoreId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mStoreId = "YOUR_STORE_ID_HERE"; // Replace with your store ID
        setupBillingClient();
    }

    private void setupBillingClient() {
        mBillingClient = BillingClient.newBuilder(this)
               .setAppId("YOUR_APP_ID_HERE") // Replace with your app ID
               .setStoreId(mStoreId)
               .build();

        mBillingClient.setBillingSetupCallback(new BillingClientSetupCallback() {
            @Override
            public void onBillingSetupFinished(BillingResult billingResult) {
                if (billingResult.isSuccess()) {
                    Log.d("BillingClient", "Setup finished");
                } else {
                    Log.d("BillingClient", "Setup failed: " + billingResult.getStatus());
                }
            }
        }, null);
    }

    // Other methods...
}

Make a purchase

To make a purchase, you can use the purchaseItemAsync method:

mBillingClient.purchaseItemAsync(mStoreId, "YOUR_ITEM_ID_HERE", 1)
       .setResultCallback(new ResultCallback() {
            @Override
            public void onResult(int result, String message) {
                if (result == BillingClient.BillingResult.PURCHASE_ITEM_SUCCESS) {
                    Log.d("BillingClient", "Purchase successful");
                } else if (result == BillingClient.BillingResult.PURCHASE_ITEM_FAILED) {
                    Log.d("BillingClient", "Purchase failed: " + message);
                }
            }
        });

 Get the purchase details

To get the purchase details, you can use the getPurchaseDetailsAsync method:

mBillingClient.getPurchaseDetailsAsync(mStoreId, "YOUR_ITEM_ID_HERE")
       .setResultCallback(new ResultCallback() {
            @Override
            public void onResult(int result, PurchaseDetails details) {
                if (result == BillingClient.BillingResult.PURCHASE_DETAILS_SUCCESS) {
                    Log.d("BillingClient", "Purchase details: " + details.getPurchaseToken());
                } else if (result == BillingClient.BillingResult.PURCHASE_DETAILS_FAILED) {
                    Log.d("BillingClient", "Purchase details failed: " + details.getErrorMessage());
                }
            }
        });

 

5. Google Cloud Messaging (GCM) / Firebase Cloud Messaging (FCM)

Enables apps to send push notifications and data payloads to devices.

Add dependencies

In your build.gradle file, add the following dependencies:

dependencies {
    implementation 'com.google.firebase:firebase-messaging:22.0.1'
}

Initialize FCM in your Activity

In your MainActivity, initialize the FCM:

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Bundle;
import android.util.Log;

import com.google.firebase.messaging.FirebaseMessaging;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Initialize FCM
        FirebaseMessaging.getInstance().subscribeToTopic("your_topic");
    }

    @Override
    protected void onResume() {
        super.onResume();

        // Register for FCM notifications
        FirebaseMessaging.getInstance().getToken()
               .addOnCompleteListener(new OnCompleteListener<String>() {
                    @Override
                    public void onComplete(@NonNull Task<String> task) {
                        if (!task.isSuccessful()) {
                            Log.w(TAG, "Failed to get token for FCM");
                            return;
                        }

                        // Get the token
                        String token = task.getResult();
                        Log.d(TAG, "FCM Token: " + token);

                        // Send the token to your server
                    }
                });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        // Unsubscribe from FCM topics when the activity is destroyed
        FirebaseMessaging.getInstance().unsubscribeFromTopic("your_topic");
    }
}

Create a notification channel

Create a notification channel in your MainActivity:

import android.os.Build;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Create a notification channel
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel("your_channel_id");
            channel.setDescription("Your notification channel description");

            // Register the channel
            NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            manager.createNotificationChannel(channel);
        }
    }
}

 Send a notification

To send a notification, use the following code:

import android.os.Bundle;
import android.util.Log;

import com.google.firebase.messaging.FirebaseMessaging;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Send a notification
        FirebaseMessaging.getInstance().send(new RemoteMessage.Builder()
               .setTopic("your_topic")
               .addData("message", "Hello, world!")
               .build());
    }
}

6. Google Drive API

Facilitates integration with Google Drive for saving and retrieving files from cloud storage.

Add necessary dependencies

In your build.gradle file, add the following dependencies:

dependencies {
    implementation 'com.google.android.gms:play-services-drive:22.0.1'
}

 Create a Google Drive API project

You will need a new project in the Google Cloud Console and enable the Google Drive API. Create credentials for your project, such as a service account key file.

 Initialize the Google Drive API

In your Android activity, initialize the Google Drive API:

import com.google.android.gms.drive.DriveApi;
import com.google.android.gms.drive.DriveFile;
import com.google.android.gms.drive.DriveMetadata;
import com.google.android.gms.drive.DriveServiceException;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Initialize the Google Drive API
        DriveApi.initialize(this, "YOUR_SERVICE_ACCOUNT_KEY_FILE");
    }
}

Create a new file

Create a new file using the Google Drive API:

import com.google.android.gms.drive.DriveApi;
import com.google.android.gms.drive.DriveFile;
import com.google.android.gms.drive.DriveMetadata;
import com.google.android.gms.drive.DriveServiceException;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Initialize the Google Drive API
        DriveApi.initialize(this, "YOUR_SERVICE_ACCOUNT_KEY_FILE");

        // Create a new file
        DriveFile driveFile = new DriveFile("example.txt");
        try {
            DriveApi.newDriveFile(this, driveFile).setMetadata(new DriveMetadata("example.txt")).execute();
        } catch (DriveServiceException e) {
            Log.e(TAG, "Error creating file: " + e.getMessage());
        }
    }
}

List files

List all the files in your Google Drive account:

import com.google.android.gms.drive.DriveApi;
import com.google.android.gms.drive.DriveFile;
import com.google.android.gms.drive.DriveMetadata;
import com.google.android.gms.drive.DriveServiceException;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Initialize the Google Drive API
        DriveApi.initialize(this, "YOUR_SERVICE_ACCOUNT_KEY_FILE");

        // List all files
        DriveFile[] driveFiles = new DriveApi().files().list(this).execute();
        for (DriveFile file : driveFiles) {
            Log.d(TAG, "File: " + file.getName());
        }
    }
}

7. Google Cast

Supports media streaming to Google Cast-enabled devices, such as Chromecast.

8. Google Fit

Integrates health and fitness data from wearables or apps into a centralized location for health monitoring and analysis.

9. Google Nearby

Provides APIs for communication between nearby devices, including location-based notifications and peer-to-peer connections.

10. Google Pay

Enables payment processing within apps using the Google Pay system, allowing users to make secure transactions.

11. AdMob

Allows developers to include in-app advertising through Google’s ad network.

12. SafetyNet

Offers various security-related services, including app attestation, reCAPTCHA, and device integrity checks to ensure the security of the app and device.

13. Google Analytics for Firebase

Allows developers to track user interactions within their apps, giving them insights into user behavior and app performance.

14. Wear OS Integration

Provides APIs for integrating with Wear OS devices, enabling apps to work with wearable technology.

15. Google Play Games Services

Facilitates features like leaderboards, achievements, multiplayer gaming, and other game-related functionalities.

Conclusion

Targeting any other App Store than Google’s may leave you without all of the above. This is one of the reasons WHY (besides the monetary side) – most app developers prefer first targeting the Apple App Platform

  • What are ways to Optimize the backend endpoints in Spring Boot
  • Flutter image flickers
  • Could a Flutter App save a Flag even after uninstall
  • Could iOS flutter app logs be viewed while running in release mode – started after previous closed state
  • 6 Addictive Mobile Game Ideas Inspired by Flappy Bird’s Simplicity

Categories

  • Apps (20)
  • ChatGPT (19)
  • Choosing a Framework (38)
  • Flutter (206)
  • Graphical User Interface (13)
  • Marketing (114)
  • Software Development (270)
  • Spring (43)
  • StartUp (21)
  • Uncategorized (4)
  • Uncategorized (15)
  • Vaadin (14)

Tags

Algorithms (9) crypto (29) flutterdev (39) General (86) Java (7) QR & Bar Codes (3) Software Dev Choices (33) Spring Boot (1) standards (1) Theme (3) User Authentication & Authorization (9) User Experience (10) Utilities (19) WordPress (11)

Product categories

  • All Technologies (83)
    • Flutter Apps (23)
    • GPT (4)
    • Java (38)
    • Native Android (3)
    • PHP (9)
    • Spring (Boot) / Quarkus (35)
    • Utils (15)
    • Vaadin 24+ (27)
    • Vaadin 8 (1)
  • Apps (18)
    • Employees DB (1)
    • Notes (6)
    • Personal Budget (1)
    • Recipes Book (1)
    • Stuff Organizer (1)
    • To-Do (2)
  • PDF Books (3)
  • Source Code Generators (8)

Recent Posts

  • What are ways to Optimize the backend endpoints in Spring Boot
  • Flutter image flickers
  • Could a Flutter App save a Flag even after uninstall
  • Could iOS flutter app logs be viewed while running in release mode – started after previous closed state
  • 6 Addictive Mobile Game Ideas Inspired by Flappy Bird’s Simplicity

Post Categories

  • Apps (20)
  • ChatGPT (19)
  • Choosing a Framework (38)
  • Flutter (206)
  • Graphical User Interface (13)
  • Marketing (114)
  • Software Development (270)
  • Spring (43)
  • StartUp (21)
  • Uncategorized (4)
  • Uncategorized (15)
  • Vaadin (14)