- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我开发了一个应用程序来获取当前位置,但是我没有得到任何位置信息,我也尝试了 GoogleService failed to initialize 中的解决方案但它对我不起作用。
这是我的主要 Activity :
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.drive.Drive;
import com.google.android.gms.location.LocationServices;
public class GetLocation extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
public GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_get_location);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
// mGoogleApiClient = new GoogleApiClient.Builder(this)
// .addApi(Drive.API)
// .addScope(Drive.SCOPE_FILE)
// .build();
// Create an instance of GoogleAPIClient.
//if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
// }
}
protected void onStart() {
mGoogleApiClient.connect();
super.onStart();
}
protected void onStop() {
mGoogleApiClient.disconnect();
super.onStop();
}
@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_get_location, 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 connectionHint) {
Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
if (mLastLocation != null) {
TextView mLatitudeText = (TextView) findViewById(R.id.mLatitudeText);
TextView mLongitudeText = (TextView) findViewById(R.id.mLongitudeText);
mLatitudeText.setText(String.valueOf(mLastLocation.getLatitude()));
mLongitudeText.setText(String.valueOf(mLastLocation.getLongitude()));
}
}
@Override
public void onConnectionSuspended(int i) {
TextView mLatitudeText = (TextView) findViewById(R.id.mLatitudeText);
TextView mLongitudeText = (TextView) findViewById(R.id.mLongitudeText);
mLatitudeText.setText("onConnectionSuspended");
mLongitudeText.setText("onConnectionSuspended");
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
TextView mLatitudeText = (TextView) findViewById(R.id.mLatitudeText);
TextView mLongitudeText = (TextView) findViewById(R.id.mLongitudeText);
mLatitudeText.setText(String.valueOf(connectionResult));
mLongitudeText.setText("onConnectionFailed");
}
}
这是我的 Logcat
:
12-29 01:16:41.170 14919-14919/? D/AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
12-29 01:16:41.170 14919-14919/? D/AndroidRuntime: CheckJNI is ON
12-29 01:16:41.200 14919-14919/? D/ICU: No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
12-29 01:16:41.230 14919-14919/? E/memtrack: Couldn't load memtrack module (No such file or directory)
12-29 01:16:41.230 14919-14919/? E/android.os.Debug: failed to load memtrack module: -2
12-29 01:16:41.240 14919-14919/? I/Radio-JNI: register_android_hardware_Radio DONE
12-29 01:16:41.250 14919-14919/? D/AndroidRuntime: Calling main entry com.android.commands.am.Am
12-29 01:16:41.250 1358-1791/system_process I/ActivityManager: Force stopping com.timesavii.getlocation appid=10043 user=0: from pid 14919
12-29 01:16:41.250 1358-1791/system_process I/ActivityManager: Killing 14857:com.timesavii.getlocation/u0a43 (adj 0): stop com.timesavii.getlocation
12-29 01:16:41.280 1358-1394/system_process W/InputDispatcher: channel '683d475 com.timesavii.getlocation/com.timesavii.getlocation.GetLocation (server)' ~ Consumer closed input channel or an error occurred. events=0x9
12-29 01:16:41.280 1358-1394/system_process E/InputDispatcher: channel '683d475 com.timesavii.getlocation/com.timesavii.getlocation.GetLocation (server)' ~ Channel is unrecoverably broken and will be disposed!
12-29 01:16:41.280 1358-1596/system_process D/GraphicsStats: Buffer count: 2
12-29 01:16:41.280 1358-1596/system_process I/WindowState: WIN DEATH: Window{683d475 u0 com.timesavii.getlocation/com.timesavii.getlocation.GetLocation}
12-29 01:16:41.280 1358-1596/system_process W/InputDispatcher: Attempted to unregister already unregistered input channel '683d475 com.timesavii.getlocation/com.timesavii.getlocation.GetLocation (server)'
12-29 01:16:41.300 1358-1791/system_process W/ActivityManager: Force removing ActivityRecord{afb69f2 u0 com.timesavii.getlocation/.GetLocation t91}: app died, no saved state
12-29 01:16:41.310 14919-14919/? D/AndroidRuntime: Shutting down VM
12-29 01:16:41.320 1358-1789/system_process W/ActivityManager: Spurious death for ProcessRecord{9193003 0:com.timesavii.getlocation/u0a43}, curProc for 14857: null
12-29 01:16:41.390 1688-1978/com.google.android.googlequicksearchbox W/EGL_emulation: eglSurfaceAttrib not implemented
12-29 01:16:41.390 1688-1978/com.google.android.googlequicksearchbox W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xe12b8480, error=EGL_SUCCESS
12-29 01:16:42.200 14928-14928/? D/AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
12-29 01:16:42.200 14928-14928/? D/AndroidRuntime: CheckJNI is ON
12-29 01:16:42.210 14932-14932/? D/AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
12-29 01:16:42.210 14932-14932/? D/AndroidRuntime: CheckJNI is ON
12-29 01:16:42.240 14928-14928/? D/ICU: No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
12-29 01:16:42.270 14928-14928/? E/memtrack: Couldn't load memtrack module (No such file or directory)
12-29 01:16:42.270 14928-14928/? E/android.os.Debug: failed to load memtrack module: -2
12-29 01:16:42.280 14932-14932/? D/ICU: No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
12-29 01:16:42.290 14928-14928/? I/Radio-JNI: register_android_hardware_Radio DONE
12-29 01:16:42.310 14928-14928/? D/AndroidRuntime: Calling main entry com.android.commands.wm.Wm
12-29 01:16:42.340 14932-14932/? E/memtrack: Couldn't load memtrack module (No such file or directory)
12-29 01:16:42.340 14932-14932/? E/android.os.Debug: failed to load memtrack module: -2
12-29 01:16:42.350 14932-14932/? I/Radio-JNI: register_android_hardware_Radio DONE
12-29 01:16:42.370 14932-14932/? D/AndroidRuntime: Calling main entry com.android.commands.am.Am
12-29 01:16:42.380 1358-1370/system_process I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.timesavii.getlocation/.GetLocation} from uid 0 on display 0
12-29 01:16:43.560 1358-1488/system_process W/InputMethodManagerService: Got RemoteException sending setActive(false) notification to pid 14857 uid 10043
12-29 01:16:43.560 14928-14928/? D/AndroidRuntime: Shutting down VM
12-29 01:16:43.560 1358-1371/system_process W/art: Long monitor contention event with owner method=com.android.internal.view.InputBindResult com.android.server.InputMethodManagerService.windowGainedFocus(com.android.internal.view.IInputMethodClient, android.os.IBinder, int, int, int, android.view.inputmethod.EditorInfo, com.android.internal.view.IInputContext) from InputMethodManagerService.java:2177 waiters=0 for 2.010s
12-29 01:16:43.560 1688-1688/com.google.android.googlequicksearchbox I/Choreographer: Skipped 128 frames! The application may be doing too much work on its main thread.
12-29 01:16:43.590 1358-1372/system_process W/art: Long monitor contention event with owner method=int com.android.server.am.ActivityStackSupervisor.startActivityMayWait(android.app.IApplicationThread, int, java.lang.String, android.content.Intent, java.lang.String, android.service.voice.IVoiceInteractionSession, com.android.internal.app.IVoiceInteractor, android.os.IBinder, java.lang.String, int, int, android.app.ProfilerInfo, android.app.IActivityManager$WaitResult, android.content.res.Configuration, android.os.Bundle, boolean, int, android.app.IActivityContainer, com.android.server.am.TaskRecord) from ActivityStackSupervisor.java:946 waiters=0 for 750ms
12-29 01:16:43.590 14932-14932/? D/AndroidRuntime: Shutting down VM
12-29 01:16:43.650 1861-1861/com.google.android.googlequicksearchbox:search W/LocationOracleImpl: Best location was null
12-29 01:16:43.700 1861-14948/com.google.android.googlequicksearchbox:search I/HotwordRecognitionRnr: Starting hotword detection.
12-29 01:16:43.730 1861-14950/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_starting com.google.android.apps.gsa.speech.audio.u@f8a6cc8
12-29 01:16:43.740 1042-1708/? E/audio_hw_generic: Error opening input stream format 1, channel_mask 0010, sample_rate 16000
12-29 01:16:43.740 1042-14952/? I/AudioFlinger: AudioFlinger's thread 0xf3700000 ready to run
12-29 01:16:43.770 1861-14950/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_started com.google.android.apps.gsa.speech.audio.u@f8a6cc8
12-29 01:16:43.770 1861-2330/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_close com.google.android.apps.gsa.speech.audio.u@f8a6cc8
12-29 01:16:43.770 1861-14950/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error -4 during AudioRecord native read
12-29 01:16:43.770 14953-14953/? I/art: Not late-enabling -Xcheck:jni (already on)
12-29 01:16:43.780 1358-1738/system_process I/ActivityManager: Start proc 14953:com.timesavii.getlocation/u0a43 for activity com.timesavii.getlocation/.GetLocation
12-29 01:16:43.860 1861-2333/com.google.android.googlequicksearchbox:search I/HotwordRecognitionRnr: Stopping hotword detection.
12-29 01:16:43.980 1861-14948/com.google.android.googlequicksearchbox:search I/HotwordRecognitionRnr: Hotword detection finished
12-29 01:16:44.020 1688-1978/com.google.android.googlequicksearchbox E/Surface: getSlotFromBufferLocked: unknown buffer: 0xe12a3690
12-29 01:16:44.060 1861-1871/com.google.android.googlequicksearchbox:search I/art: Background sticky concurrent mark sweep GC freed 3331(258KB) AllocSpace objects, 0(0B) LOS objects, 9% free, 4MB/5MB, paused 80ms total 330ms
12-29 01:16:44.070 14953-14953/com.timesavii.getlocation W/System: ClassLoader referenced unknown path: /data/app/com.timesavii.getlocation-1/lib/x86_64
12-29 01:16:44.100 14953-14953/com.timesavii.getlocation I/GMPM: App measurement is starting up, version: 8487
12-29 01:16:44.100 14953-14953/com.timesavii.getlocation I/GMPM: To enable debug logging run: adb shell setprop log.tag.GMPM VERBOSE
12-29 01:16:44.100 14953-14953/com.timesavii.getlocation E/GMPM: GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services. Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin.
12-29 01:16:44.100 14953-14953/com.timesavii.getlocation E/GMPM: Scheduler not set. Not logging error/warn.
12-29 01:16:44.130 14953-14969/com.timesavii.getlocation E/GMPM: Uploading is not possible. App measurement disabled
12-29 01:16:44.230 14953-14963/com.timesavii.getlocation I/art: Background sticky concurrent mark sweep GC freed 15526(955KB) AllocSpace objects, 3(60KB) LOS objects, 52% free, 1833KB/3MB, paused 10ms total 20ms
12-29 01:16:44.270 1030-1181/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
12-29 01:16:44.270 14953-14978/com.timesavii.getlocation D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
12-29 01:16:44.370 14953-14978/com.timesavii.getlocation I/OpenGLRenderer: Initialized EGL, version 1.4
12-29 01:16:44.410 14953-14978/com.timesavii.getlocation W/EGL_emulation: eglSurfaceAttrib not implemented
12-29 01:16:44.410 14953-14978/com.timesavii.getlocation W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f382e3bcc00, error=EGL_SUCCESS
12-29 01:16:44.540 1950-2017/com.google.android.gms.persistent W/GCoreFlp: No location to return for getLastLocation()
12-29 01:16:44.640 1358-1370/system_process D/WifiService: acquireWifiLockLocked: WifiLock{NlpWifiLock type=2 binder=android.os.BinderProxy@f597139}
12-29 01:16:44.730 1950-2017/com.google.android.gms.persistent W/GCoreFlp: No location to return for getLastLocation()
12-29 01:16:44.790 1358-1377/system_process I/ActivityManager: Displayed com.timesavii.getlocation/.GetLocation: +1s30ms
12-29 01:16:45.040 1950-2017/com.google.android.gms.persistent W/GCoreFlp: No location to return for getLastLocation()
12-29 01:16:45.080 1358-1791/system_process D/WifiService: releaseWifiLockLocked: WifiLock{NlpWifiLock type=2 binder=android.os.BinderProxy@f597139}
12-29 01:16:54.280 14953-14969/com.timesavii.getlocation I/GMPM: Tag Manager is not found and thus will not be used
12-29 01:19:27.090 1358-1371/system_process I/UsageStatsService: User[0] Flushing usage stats to disk
12-29 01:21:29.890 1358-1369/system_process D/WifiService: acquireWifiLockLocked: WifiLock{NlpWifiLock type=2 binder=android.os.BinderProxy@f597139}
12-29 01:21:29.900 1358-1488/system_process D/WifiService: releaseWifiLockLocked: WifiLock{NlpWifiLock type=2 binder=android.os.BinderProxy@f597139}
最佳答案
对于当前位置,你可以试试这个代码:
LocationManager location_manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener listner = new MyLocationListener();
location_manager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 2000, 2000, listner);
location_manager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
public class MyLocationListener implements LocationListener {
StringBuilder str;
@Override
public void onLocationChanged(Location arg0) {
latitude = arg0.getLatitude();
longitude = arg0.getLongitude();
try {
geocoder = new Geocoder(MainActivity.this, Locale.ENGLISH);
addresses = geocoder.getFromLocation(latitude, longitude, 1);
if (geocoder.isPresent()) {
Address returnAddress = addresses.get(0);
String city = returnAddress.getLocality();
String zipCode = returnAddress.getPostalCode();
}
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onProviderDisabled(String arg0) {
}
@Override
public void onProviderEnabled(String arg0) {
}
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
}
}
关于java - getLastLocation 谷歌服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34505665/
我正在编写一个具有以下签名的 Java 方法。 void Logger(Method method, Object[] args); 如果一个方法(例如 ABC() )调用此方法 Logger,它应该
我是 Java 新手。 我的问题是我的 Java 程序找不到我试图用作的图像文件一个 JButton。 (目前这段代码什么也没做,因为我只是得到了想要的外观第一的)。这是我的主课 代码: packag
好的,今天我在接受采访,我已经编写 Java 代码多年了。采访中说“Java 垃圾收集是一个棘手的问题,我有几个 friend 一直在努力弄清楚。你在这方面做得怎么样?”。她是想骗我吗?还是我的一生都
我的 friend 给了我一个谜语让我解开。它是这样的: There are 100 people. Each one of them, in his turn, does the following
如果我将使用 Java 5 代码的应用程序编译成字节码,生成的 .class 文件是否能够在 Java 1.4 下运行? 如果后者可以工作并且我正在尝试在我的 Java 1.4 应用程序中使用 Jav
有关于why Java doesn't support unsigned types的问题以及一些关于处理无符号类型的问题。我做了一些搜索,似乎 Scala 也不支持无符号数据类型。限制是Java和S
我只是想知道在一个 java 版本中生成的字节码是否可以在其他 java 版本上运行 最佳答案 通常,字节码无需修改即可在 较新 版本的 Java 上运行。它不会在旧版本上运行,除非您使用特殊参数 (
我有一个关于在命令提示符下执行 java 程序的基本问题。 在某些机器上我们需要指定 -cp 。 (类路径)同时执行java程序 (test为java文件名与.class文件存在于同一目录下) jav
我已经阅读 StackOverflow 有一段时间了,现在我才鼓起勇气提出问题。我今年 20 岁,目前在我的家乡(罗马尼亚克卢日-纳波卡)就读 IT 大学。足以介绍:D。 基本上,我有一家提供簿记应用
我有 public JSONObject parseXML(String xml) { JSONObject jsonObject = XML.toJSONObject(xml); r
我已经在 Java 中实现了带有动态类型的简单解释语言。不幸的是我遇到了以下问题。测试时如下代码: def main() { def ks = Map[[1, 2]].keySet()
一直提示输入 1 到 10 的数字 - 结果应将 st、rd、th 和 nd 添加到数字中。编写一个程序,提示用户输入 1 到 10 之间的任意整数,然后以序数形式显示该整数并附加后缀。 public
我有这个 DownloadFile.java 并按预期下载该文件: import java.io.*; import java.net.URL; public class DownloadFile {
我想在 GUI 上添加延迟。我放置了 2 个 for 循环,然后重新绘制了一个标签,但这 2 个 for 循环一个接一个地执行,并且标签被重新绘制到最后一个。 我能做什么? for(int i=0;
我正在对对象 Student 的列表项进行一些测试,但是我更喜欢在 java 类对象中创建硬编码列表,然后从那里提取数据,而不是连接到数据库并在结果集中选择记录。然而,自从我这样做以来已经很长时间了,
我知道对象创建分为三个部分: 声明 实例化 初始化 classA{} classB extends classA{} classA obj = new classB(1,1); 实例化 它必须使用
我有兴趣使用 GPRS 构建车辆跟踪系统。但是,我有一些问题要问以前做过此操作的人: GPRS 是最好的技术吗?人们意识到任何问题吗? 我计划使用 Java/Java EE - 有更好的技术吗? 如果
我可以通过递归方法反转数组,例如:数组={1,2,3,4,5} 数组结果={5,4,3,2,1}但我的结果是相同的数组,我不知道为什么,请帮助我。 public class Recursion { p
有这样的标准方式吗? 包括 Java源代码-测试代码- Ant 或 Maven联合单元持续集成(可能是巡航控制)ClearCase 版本控制工具部署到应用服务器 最后我希望有一个自动构建和集成环境。
我什至不知道这是否可能,我非常怀疑它是否可能,但如果可以,您能告诉我怎么做吗?我只是想知道如何从打印机打印一些文本。 有什么想法吗? 最佳答案 这里有更简单的事情。 import javax.swin
我是一名优秀的程序员,十分优秀!