我一直在关注 2 个教程,但都没有工作,我确保我添加了权限和依赖项。
这是我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_get_location);
mTextView = (TextView) findViewById(R.id.text);
gps_loc = (TextView) findViewById(R.id.location);
gps_btn = (Button) findViewById(R.id.gps_btn);
next_act = (Button) findViewById(R.id.next_activity);
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
gps_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Build.VERSION.SDK_INT >= 26) {
if (getApplicationContext().checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(get_location.this, "Got Permission", Toast.LENGTH_SHORT).show();
fusedLocationProviderClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if(location != null)
{
Double lat = location.getLatitude();
Double longt = location.getLongitude();
gps_loc.setText(lat+","+longt);
}
}
});
}
}
else
{
ActivityCompat.requestPermissions(get_location.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
}
}
});
next_act.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(get_location.this, circular_menu_external.class);
startActivity(intent);
}
});
}
}
我想了解在我制作的名为 gps_loc 的文本视图中显示 GPS 位置所必需的。
我拥有的智能手表是 Mobvoi 的 S2 TicWatch mad eby,是的,它确实包含 GPS 功能。我需要在我的 textView 中显示 GPS 等内容,但 GPS 位于我的列表顶部,但似乎没有任何效果。而且我不知道问题出在哪里或它是什么。
依赖项:
implementation 'com.google.android.support:wearable:2.8.1'
implementation 'com.google.android.gms:play-services-wearable:17.0.0'
implementation 'androidx.percentlayout:percentlayout:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.wear:wear:1.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation project(path: ':lvl_library')
implementation 'com.google.android.gms:play-services-location:18.0.0'
compileOnly 'com.google.android.wearable:wearable:2.8.1'
清单文件中的权限:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />