Step 1 :- Create New Android Project.
Step 2 :- Add Google-play-services_lib to your project.
Step 3 :- Open AndroidManifest.xml file.
<!--?xml version="1.0" encoding="utf-8"?--> package="com.mapv2.demo" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.mapv2.demo.MainActivity" android:label="@string/app_name" >
Step 4 :- Open activity_main.xml.
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <TextView android:id="@+id/tv_status" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" />
Step 5 :- Open MainActivity.java
package com.mapv2.demo; import android.app.Activity; import android.app.Dialog; import android.os.Bundle; import android.view.Menu; import android.widget.TextView; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; public class MainActivity extends Activity { @Override protected void onResume() { super.onResume(); // Getting reference to TextView to show the status TextView tvStatus = (TextView)findViewById(R.id.tv_status); // Getting status int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext()); // Showing status if(status==ConnectionResult.SUCCESS) tvStatus.setText("Google Play Services are available"); else{ tvStatus.setText("Google Play Services are not available"); int requestCode = 10; Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode); dialog.show(); } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
Step 6 :- Run Code.
Leave a Reply