安卓這里報錯,怎么回事,謝謝
uj5u.com熱心網友回復:
package com.example.myapplication1;import android.annotation.SuppressLint;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.provider.Settings;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity implements LocationListener {
static final int MIN_TIME=5000;
static final float MIN_DIST=5;
LocationManager mgr;
TextView txv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txv= findViewById(R.id.textView3);
mgr= (LocationManager) getSystemService(LOCATION_SERVICE);
}
protected void onResume() {
super.onResume();
String best=mgr.getBestProvider(new Criteria(),true);
if (best !=null){
mgr.requestLocationUpdates(best,MIN_TIME,MIN_DIST,this);
mgr.
}
}
@Override
public void onLocationChanged(Location location) {
String str="定位提供者:"+location.getProvider();
str+=String.format("\n維度::%.5f\n經度::%.5f\n高度::%.2f米",
location.getLatitude(),
location.getLongitude(),
location.getAltitude());
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
@Override
public void onProviderEnabled(String s) {
}
@Override
public void onProviderDisabled(String s) {
}
public void setup(View v){
Intent it=new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(it);
}
}
uj5u.com熱心網友回復:
滑鼠移到錯誤代碼上去會有錯誤資訊,發出來看看轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/59897.html
標籤:Android
