如果你想跟蹤android上的位置,你必須在設置中打開跟蹤器。據我所知,沒有辦法自動做到這一點。
因此,直接回答你的問題,沒有辦法做到這一點。標準解決方案是要求用戶打開跟蹤並打開設置菜單。
例如:
/**
* Function to show settings alert dialog
* */
public void showSettingsAlert(){
AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
// Setting Dialog Title
alertDialog.setTitle("GPS is settings");
// Setting Dialog Message
alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");
// Setting Icon to Dialog
//alertDialog.setIcon(R.drawable.delete);
// On pressing Settings button
alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
mContext.startActivity(intent);
}
});
// on pressing cancel button
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
// Showing Alert Message
alertDialog.show();
}
這是鏈接到教程: http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/
https://kjthumar.blogspot.de/2016/04/android-google-fusedlocationproviderapi.html?view = flipcard 檢查此鏈接。 –
使用NETWORK_PROVIDER如果你不想把你的Gps .. – rafsanahmad007
最終轉向NETWORK_PROVIDER。這很簡單。我的應用已經需要互聯網。我發現GoogleApiClient LocationService具有更高的準確性。這就是我爲什麼要使用它的原因。感謝您寶貴的回覆。 –