0
我有一個應用程序,當我們點擊一個按鈕的應用程序啓動谷歌地圖與搜索查詢。但我需要打開該位置才能提供準確的結果。可能嗎?如何提示用戶打開位置?
我有一個應用程序,當我們點擊一個按鈕的應用程序啓動谷歌地圖與搜索查詢。但我需要打開該位置才能提供準確的結果。可能嗎?如何提示用戶打開位置?
您應該在您的AndroidManifest.xml中添加permission。
有關Android權限的一般信息here。
請注意Android 6權限機制已更改(it became iOS like)。
我明白您的查詢 這裏是應該在你的onCreate方法可以添加代碼
LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER) ||
!lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
// Build the alert dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Location Services Not Active");
builder.setMessage("Please enable Location Services and GPS");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
// Show location settings when the user acknowledges the alert dialog
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
});
Dialog alertDialog = builder.create();
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.show();
}
這是你的答案:http://stackoverflow.com/a/33408809/1281180 – Blackkara
的可能的複製HTTP ://stackoverflow.com/questions/3470693/android-get-location-or-prompt-to-enable-location-service-if-disabled – abielita