How To Setup Google Play Service Android Studio
By integrating your Android apps with the Google Play Services, you can access Google services, such as Maps, Bulldoze, and Google+. One time you have your apps ready to use these services, accessing them is typically straightforward. The setup process does crave a few steps, just y'all just demand to conduct them out in one case. In this tutorial we volition become through the process of integrating Google Play Services with Android apps.
Introduction
Throughout the tutorial, we volition outline what you need to practise to integrate apps with Play Services in both Eclipse and Android Studio. You volition need admission to the Google Developer Console and to the Keytool utility.
In one case y'all are ready with Play Services, the development procedure itself will exist determined past what yous want your apps to practise. The the setup procedure, still, remains the same. Past using the client library to access platform services, your apps volition benefit from automatic updates through the Play Store.
i. Install Play Services in your IDE
Step 1
Open your IDE and start the Android SDK Managing director. In Eclipse, cull Window >Android > SDK Manager. In Android Studio, click the SDK Managing director toolbar push. Scroll through the list, expand the Extras folder and select Google Play Services.
Click to install the package and take the license when you are prompted. If you are developing in Android Studio, you will also need to install the Google Repository.
Step two
When yous test apps in which you use the Google Play Services APIs, ideally, yous should run them on physical devices. Yet, it is possible to test in the emulator. To exercise this, yous will need to install the Google APIs Platform. You will find this inside the directory for any of the API levels 17 and upward.
Detect the platform in your SDK Managing director, install it, and accept the license. When yous create an AVD (Android Virtual Device) to test an app using Google Play Services, cull Google APIs equally the target.
Step iii
If you are developing in Eclipse, you lot will also demand to copy the Play Services library into your workspace. First, browse to information technology on your figurer using a file explorer. Y'all volition notice information technology in the folder you lot downloaded your Android SDK into, at /extras/google/google_play_services/libproject/google-play-services_lib/
.
Re-create it to a location on your computer that you use for Android development files. Once y'all take copied the library (you must copy information technology rather than using the version in the SDK directory), go back to Eclipse. Choose Importfrom theFile menu. Aggrandize the Android folder, select Existing Android Code Into Workspace, and click Next.
Click the Browse push and navigate to the location you copied the Play Services library into. Select the binder you copied and click Finish to import it. The package will announced in your Bundle Explorer.
ii. Create an Android Projection
Step 1
You tin now kickoff developing with the Play Services resources. Create a new Android project in your IDE. Once you have a project in your workspace, you need to reference the Play Services resources within information technology.
In Android Studio, yous volition need to add together a build rule to the build.gradle file in the module for your application project. In the dependencies
section, utilise the following syntax:
compile 'com.google.android.gms:play-services:four.ane.32'
Brand sure you utilize the number for the most recent version of Play Services. Y'all will need to update this as the library is updated. Save the file and click the Sync Projection with Gradle Files push button.
In Eclipse, select the project in your Package Explorer, right-click or select the Projection menu, and cull Properties. Select the Android option on the left and click Add in the Library section.
Select the Google Play Services library from the pop-up window and click OK to add it. ClickApply and theOK.
Step ii
Whichever IDE y'all are using, y'all will need to add together Play Services meta-data to your manifest file. Open the project's manifest file and add together the meta-data element inside the awarding
element:
<meta-information android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
If y'all are using Proguard, y'all volition need to create an exception. Come across the Developer Guide for more details. For an overview of the Google Play Services APIs, check out the Package Index.
three. Connecting with Play Services in your Apps
Pace 1
The processing steps you need to take within your application lawmaking volition depend on what functionality you want to implement with Play Services. The following sections outline some general considerations and steps.
Although updates are pushed through the Google Play Shop, it is still appropriate to check what version the user device has installed before yous attempt to behave out any processing with Google Play Services.
Encounter the Implementing GCM Client example code in the Developer Guide for an overview of how to implement these checks within an Activity
class. The method call to look for is isGooglePlayServicesAvailable
, which you tin can add to a helper method as in the post-obit extract:
private boolean checkPlayServices() { int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //... }
You could call the method in onCreate
, before attempting to create the GoogleAPIClient
instance through which you access the Play Services resources, and within onResume
. If the user device does not have the required resources installed, they will be prompted to exercise and then through the Google Play Store.
Step two
After checking the level of support on the user device, you can create an instance of the GoogleAPIClient
course to call on the Google Play resources. The post-obit example code demonstrates this and could be included in onCreate
:
GoogleApiClient myClient = new GoogleApiClient.Builder(this) .addApi(Plus.API) .addScope(Plus.SCOPE_PLUS_PROFILE) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build();
This would prepare your application for accessing Google+ services, equally you can meet from the Plus.API
excerpt. The addScope
line will vary depending on what your app does. This code also sets up callbacks for the connection process. Your class can implement the post-obit interfaces:
public class MainActivity extends Activity implements ConnectionCallbacks, OnConnectionFailedListener
The class tin can then implement the onConnected
and onConnectionSuspended
callbacks for handling changes in connection to Play Services.
To handle failures in connecting to Play Services, such as in cases where user sign-in is required, your grade tin can likewise implement onConnectionFailed
, for accessing diverse standard methods for resolving typical errors. Some of these methods will cause the onActivityResult
method to execute when the user returns to the app, and then y'all can reattempt to connect at that place.
In general, your Activeness
class should connect to Play Services in onStart
and disconnect in onStop
via the GoogleAPIClient
class as in the post-obit extract:
myClient.connect();
4. Using Play Services Resources
Stride 1
For sure Play Services, including Google+, you lot need to register for admission. To do then, log into the Google APIs Console, clickCreate Project, and enter a name. After creating the project, you should be redirected to the projection in the panel.
Select the APIs carte du jour detail, find Google+ API in the list, and click the button to enable it. The status should change to ON subsequently accepting the license. Clicking the API listing volition give you an overview of what yous can do with it.
Step ii
Side by side, selectCredentials and clickCreate New Client ID. Select the Installed awarding radio push button, select Android as the type, and enter your app details. Now y'all need to use the Keytool resource to generate a SHA1 certificate.
During evolution, you tin can employ the debug keystore, entering the following lawmaking in a terminal:
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -list -five
You'll need to make sure this is the correct location for your debug keystore, alter the path if information technology isn't. When you execute this command, you'll be prompted for the password. Enterandroid
for the debug keystore and the fingerprint should be output to the terminal.
Copy the SHA1
line and paste information technology into the Signing certificate fingerprint box in the APIs Console. Enable deep linking if necessary and then click the button to create the ID. A section will announced entitled Client ID for Android Application. You do not actually demand to utilize the ID in your app lawmaking, but you may wish to keep a copy of it for your own records.
Pace 3
Earlier you tin phone call on the Play Services APIs in your application code, you will need to add the appropriate permissions to your projection's manifest file. The post-obit examples demonstrate a few typical apply cases, but you will need to cull the appropriate permissions for your ain project:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:proper name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" />
Your project should at present exist configured to call the Play Services APIs that you need. You will need to structure your Action
classes differently depending on what your apps practise. Take a look at the Programmer Guide for more information well-nigh this.
Don't forget to cheque out the post-obit guides to become started with some of the available Play Services:
- Google+
- Google Drive
- Maps
- Location
- Games
- Wallet
If the Google services y'all wish to admission are non part of the Play Services library, you can access them using Google's Residual API.
Conclusion
There are a lot of possibilities with Google Play Services in Android apps. From gaming to location and mapping services, your apps can take advantage of the existing platform features inside the context of your own user interfaces and functionality.
The setup procedure may seem a little laborious, only once you're set up, you tin can focus on bringing these services to your users.
Did you lot find this mail service useful?
How To Setup Google Play Service Android Studio,
Source: https://code.tutsplus.com/tutorials/integrating-google-play-services-on-android--cms-19828#:~:text=Install%20Play%20Services%20in%20your%20IDE&text=In%20Android%20Studio%2C%20click%20the,license%20when%20you%20are%20prompted.
Posted by: guntherthust1969.blogspot.com
0 Response to "How To Setup Google Play Service Android Studio"
Post a Comment