smile908

导航

安卓获取设备的支持的定位provider和跳转到设置gsp页面

package com.example.gpsdemo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.TextView;

import java.util.List;

public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv = findViewById(R.id.tv);
LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
//获取所有系统可用的LocationProvider
List<String> providers = locManager.getAllProviders();
for (int i = 0; i < providers.size(); i++) {
tv.append(providers.get(i) + "---");
}
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
goToGpsSettings();
}
});
}
public void goToGpsSettings() {
Intent callGPSSettingIntent = new Intent(
Settings.ACTION_LOCATION_SOURCE_SETTINGS);
this.startActivity(callGPSSettingIntent);
}
}

运行结果:

 

 点击按钮后会跳转到设置的页面,如下图所示

 

 

 

posted on 2022-11-25 16:57  smile908  阅读(81)  评论(0编辑  收藏  举报