gpt4 book ai didi

java - Android LocationClient 总是连接不上

转载 作者:行者123 更新时间:2023-11-30 02:39:50 25 4
gpt4 key购买 nike

我正在尝试为个人项目实现 LocationClient,不幸的是,在调用 LocationClient 的 connect() 方法时,它总是失败。我在模拟器上试过,然后在安卓设备上试过。关于 android 设备,我只尝试使用 wifi,仅使用数据,使用 wifi 和 GPS,然后使用数据和 GPS。仍然失败...

这是我的类(class):

包com.quentin_cheval.quickpint;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient;
import com.google.android.gms.location.LocationClient;

import java.util.concurrent.ExecutionException;


public class SearchActivity extends Activity implements
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener
{

LocationClient mLocationClient;

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

TextView goTV = (TextView)findViewById(R.id.buttonGo);
goTV.setClickable(true);

goTV.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
mLocationClient = new LocationClient(SearchActivity.this, SearchActivity.this, SearchActivity.this);
mLocationClient.connect();
// Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class);
// startActivity(intent);
}
});
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.search, 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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}

@Override
public void onConnected(Bundle bundle)
{
Log.i("QUICKPINT", "CONNECTED");
}

@Override
public void onConnectionFailed(ConnectionResult connectionResult)
{
Log.i("QUICKPINT", "Fail");
}

@Override
public void onDisconnected()
{
Log.i("QUICKPINT", "DISCONNECTED");
}
}

非常感谢您的帮助!

最佳答案

检查 ConnectionResult connectionResult 以查看是否可以找到有关失败原因的更多信息。还要检查 logcat

关于java - Android LocationClient 总是连接不上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25951394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com