Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package kartik.com.myweather;
- import android.app.Activity;
- import android.location.Location;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.Button;
- import com.google.android.gms.common.ConnectionResult;
- import com.google.android.gms.common.api.GoogleApiClient;
- import com.google.android.gms.location.FusedLocationProviderApi;
- import com.google.android.gms.location.LocationServices;
- public class MainActivity extends Activity implements GoogleApiClient.ConnectionCallbacks,
- GoogleApiClient.OnConnectionFailedListener {
- GoogleApiClient mGoogleApiClient;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- mGoogleApiClient = new GoogleApiClient.Builder(this)
- .addConnectionCallbacks(this)
- .addOnConnectionFailedListener(this)
- .addApi(LocationServices.API)
- .build();
- /*
- final GoogleApiClient.Builder mGoogleApiClient = new GoogleApiClient.Builder(this)
- .addConnectionCallbacks(this)
- .addOnConnectionFailedListener(this)
- .addApi(LocationServices.API);
- */
- Button button = (Button) findViewById(R.id.button);
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v)
- {
- //mGoogleApiClient.build();
- }
- });
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- @Override
- public void onConnected(Bundle bundle) {
- Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
- mGoogleApiClient);
- Log.e("Location", mLastLocation.toString());
- }
- @Override
- public void onConnectionSuspended(int i) {
- }
- @Override
- public void onConnectionFailed(ConnectionResult connectionResult) {
- Log.e("connection failed", connectionResult.toString());
- }
- }
- -------------------------------------------------------------------------------------------------------------------------------
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="kartik.com.myweather" >
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/AppTheme" >
- <activity
- android:name=".MainActivity"
- android:label="@string/app_name" >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
- </manifest>
- -------------------------------------------------------------------------------------------------------------------------------
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
- android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Click"
- android:id="@+id/button"
- android:layout_centerVertical="true"
- android:layout_centerHorizontal="true" />
- </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement