我在我的代碼中找不到任何錯誤,但經度和緯度未顯示。我不明白爲什麼它不顯示&這是否是一個與Android SDK 23.問題。我得到輸出爲空白屏幕。爲什麼不顯示經度和緯度
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.support.v4.app.ActivityCompat;
import android.widget.TextView;
import android.util.Log;
public class MainActivity extends Activity implements LocationListener{
protected LocationManager locationManager;
protected LocationListener locationListener;
protected Context context;
TextView txtLat;
String lat;
String provider;
protected String latitude,longitude;
protected boolean gps_enabled,network_enabled;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtLat = (TextView) findViewById(R.id.textview1);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)
{
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
}
@Override
public void onLocationChanged(Location location) {
txtLat = (TextView) findViewById(R.id.textview1);
txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude());
}
@Override
public void onProviderDisabled(String provider) {
Log.d("Latitude","disable");
}
@Override
public void onProviderEnabled(String provider) {
Log.d("Latitude","enable");
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d("Latitude","status");
}
}
xml文件
<?xml version="1.0" encoding="utf-8"?>
<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">
<TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />
</RelativeLayout>
清單文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hhjjg.myapplication" >
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
日誌文件
01-11 20:41:35.424 27160-27160/? I/art: Late-enabling -Xcheck:jni
01-11 20:41:35.774 27160-27199/com.binox.myapplication D/OpenGLRenderer: Render dirty regions requested: true
01-11 20:41:35.784 27160-27160/com.binox.myapplication D/Atlas: Validating map...
01-11 20:41:35.864 27160-27199/com.binox.myapplication I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.BR.1.1.3_RB1.05.01.00.032.017_msm8916_64_LA.BR.1.1.3_RB1__release_AU (Ie228694f41)
01-11 20:41:35.864 27160-27199/com.binox.myapplication I/Adreno-EGL: OpenGL ES Shader Compiler Version: E031.25.03.04
01-11 20:41:35.864 27160-27199/com.binox.myapplication I/Adreno-EGL: Build Date: 09/29/15 Tue
01-11 20:41:35.864 27160-27199/com.binox.myapplication I/Adreno-EGL: Local Branch: mybranch14662643
01-11 20:41:35.864 27160-27199/com.binox.myapplication I/Adreno-EGL: Remote Branch: quic/LA.BR.1.1.3_rb1.32
01-11 20:41:35.864 27160-27199/com.binox.myapplication I/Adreno-EGL: Local Patches: NONE
01-11 20:41:35.864 27160-27199/com.binox.myapplication I/Adreno-EGL: Reconstruct Branch: AU_LINUX_ANDROID_LA.BR.1.1.3_RB1.05.01.00.032.017 + 26a3cba + 6f69ea6 + 8bc2bc8 + 649fcde + a52cccf + dbf281f + 15f0bf8 + 8d02f76 + 9b2cb1a + 25f3b04 + 7cd8c84 + b54906e + 675fd74 + 7c22ef4 + 79b094c
01-11 20:41:35.864 27160-27199/com.binox.myapplication I/OpenGLRenderer: Initialized EGL, version 1.4
01-11 20:41:35.884 27160-27199/com.binox.myapplication D/OpenGLRenderer: Enabling debug mode 0
01-11 20:41:35.884 27160-27199/com.binox.myapplication I/qdutils: PartialUpdate status: Disabled
01-11 20:41:35.884 27160-27199/com.binox.myapplication I/qdutils: Left Align: 0
01-11 20:41:35.884 27160-27199/com.binox.myapplication I/qdutils: Width Align: 0
01-11 20:41:35.884 27160-27199/com.binox.myapplication I/qdutils: Top Align: 0
01-11 20:41:35.884 27160-27199/com.binox.myapplication I/qdutils: Height Align: 0
01-11 20:41:35.884 27160-27199/com.binox.myapplication I/qdutils: Min ROI Width: 0
01-11 20:41:35.884 27160-27199/com.binox.myapplication I/qdutils: Min ROI Height: 0
01-11 20:41:35.884 27160-27199/com.binox.myapplication I/qdutils: Needs ROI Merge: 0
01-11 20:41:35.884 27160-27199/com.binox.myapplication I/qdutils: Dynamic Fps: Enabled
01-11 20:41:35.884 27160-27199/com.binox.myapplication I/qdutils: Min Panel fps: 45
01-11 20:41:35.884 27160-27199/com.binox.myapplication I/qdutils: Max Panel fps: 60
01-11 20:41:35.914 27160-27160/com.binox.myapplication I/Timeline: Timeline: Activity_idle id: [email protected] time:5478528
請顯示您的輸出。 –
@faro其空白屏幕 –
檢查你的是否。如果允許授予您可以請求位置,但您的代碼檢查您的if語句。您的陳述是「如果權限未被授予請求位置」 – nurisezgin