๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ป๊ฐœ๋ฐœ

์•ˆ๋“œ๋กœ์ด๋“œ ์›น๋ทฐ ์œ„์น˜์„œ๋น„์Šค (Android WebView Location Service)

by ๋ˆˆ๋ˆ„ :) 2023. 3. 16.

 

 

 

 

Java ์•ˆ๋“œ๋กœ์ด๋“œ ์›น๋ทฐ์—์„œ ์œ„์น˜์„œ๋น„์Šค๊ฐ€ ๊บผ์ ธ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ  ๊บผ์ ธ์žˆ์œผ๋ฉด ์œ„์น˜ ์„œ๋น„์Šค๋ฅผ Activeํ•˜๋Š” ์ฐฝ์ด ๋œจ๋„๋ก ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

 

 

private void checkLocationEnabled() {
    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    boolean gpsEnabled = false;
    boolean networkEnabled = false;

    try {
        gpsEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    try {
        networkEnabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    if (!gpsEnabled && !networkEnabled) {
        // ์œ„์น˜ ์„œ๋น„์Šค๊ฐ€ ๊บผ์ ธ์žˆ๋Š” ๊ฒฝ์šฐ
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("์œ„์น˜ ์„œ๋น„์Šค ํ™œ์„ฑํ™”");
        builder.setMessage("์ด ์•ฑ์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ์œ„์น˜ ์„œ๋น„์Šค๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์œ„์น˜ ์„œ๋น„์Šค๋ฅผ ํ™œ์„ฑํ™” ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?");
        builder.setPositiveButton("ํ™œ์„ฑํ™”", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                startActivity(intent);
            }
        });
        builder.setNegativeButton("์ทจ์†Œ", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        builder.show();
    }
}

 

 

 

 

์œ„์˜ ์ฝ”๋“œ๋ฅผ MainActivity.java์— ์žˆ๋Š” public class MainActivity extends AppCompatActivity ์•„๋ž˜์— ์ž‘์„ฑํ•˜์‹œ๊ณ 

 

 

 

 

์œ„์น˜ ์„œ๋น„์Šค๋ฅผ ํ™œ์„ฑํ™”ํ•˜๊ธฐ ์ ๋‹นํ•œ ์œ„์น˜์—์„œ

 

 

 

 

checkLocationEnabled();

 

 

 

 

์ž‘๋™์‹œ์ผœ์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.