Привет, я пытаюсь получить плавленое место для работы, но всегда получаю крах приложения, может ли кто-нибудь сказать мне wgy? бак выFused Location Crash
получаю эту ошибку:
12-11 02:08:54.525: E/AndroidRuntime(5972): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.teste/com.example.teste.MainActivity}: java.lang.IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called.
манифеста
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.teste"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.teste.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>
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
</application>
</manifest>
Главная:
package com.example.teste;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.location.LocationClient;
import android.location.Location;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener{
LocationClient mLocationClient;
Location mCurrentLocation;
TextView v1,v2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int resultCode =
GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
// If Google Play services is available
if (ConnectionResult.SUCCESS == resultCode) {
// In debug mode, log the status
Toast.makeText(this, "Serciços Google Play disponiveis", Toast.LENGTH_LONG).show(); }
mLocationClient = new LocationClient(this, this, this);
mCurrentLocation = mLocationClient.getLastLocation();
setContentView(R.layout.activity_main);
v1 = (TextView) findViewById(R.id.textView1);
v2 = (TextView) findViewById(R.id.textView2);
v1.setText(Double.toString(mCurrentLocation.getLatitude()));
v2.setText(Double.toString(mCurrentLocation.getLongitude()));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
mLocationClient.connect();
}
@Override
protected void onStop() {
mLocationClient.disconnect();
super.onStop();
}
@Override
public void onConnectionFailed(ConnectionResult arg0) {
// TODO Auto-generated method stub
}
@Override
public void onConnected(Bundle arg0) {
Toast.makeText(this, "Connected", Toast.LENGTH_SHORT).show();
}
@Override
public void onDisconnected() {
Toast.makeText(this, "Disconnected. Please re-connect.",
Toast.LENGTH_SHORT).show();
}
}
Layoout:
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="28dp"
android:layout_marginTop="21dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="32dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
Я руководствовался документацией Google, но у них был только частичный код, настолько хорошо, что это возможно, но я превзойденно перевел код на onConnected(), и никакое значение не было возвращено (извлечение широты и долготы) Также руководствовался lynda .com, который использовал метод вне onConnect() по определенному методу, созданному пользователем, изменил ли api (видео lynda.com было в марте этого года) или есть что-то еще, что нужно сделать, чтобы работать таким образом ? Tank You – Ricardo
Не обращайте внимания, я полностью забыл, что у меня было почти каждое приложение и сервис, ограниченный доступом к фоновому доступу к GPRS и игровым сервисам, где также заблокирован. Tank You – Ricardo
Но если есть какой-либо способ сделать это за пределами onConnected, пожалуйста, скажите мне. Tank You еще раз – Ricardo