Androidアプリで位置情報サービスが有効になっているかどうかを確認するにはどうすればよいですか?
この例は、Androidアプリで位置情報サービスが有効になっているかどうかを確認する方法を示しています。
ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。
ステップ2 −次のコードをres / layout / activity_main.java
に追加します。<? xml version= "1.0" encoding= "utf-8" ?> <RelativeLayout xmlns: android = "https://schemas.android.com/apk/res/android" xmlns: tools = "https://schemas.android.com/tools" android :layout_width= "match_parent" android :layout_height= "match_parent" android :layout_margin= "16dp" tools :context= ".MainActivity" > <Button android :id= "@+id/button" android :layout_width= "match_parent" android :layout_height= "wrap_content" android :text= "Enable Location" /> </RelativeLayout>
ステップ3 −次のコードをsrc / MainActivity.java
に追加しますpackage app.tutorialspoint.com.sample ;
import android.content.Context ;
import android.content.DialogInterface ;
import android.content.Intent ;
import android.location.LocationManager ;
import android.os.Bundle ;
import android.provider.Settings ;
import android.support.v7.app.AlertDialog ;
import android.support.v7.app.AppCompatActivity ;
import android.view.View ;
import android.widget.Button ;
import android.widget.TextView ;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate (Bundle savedInstanceState) {
super .onCreate(savedInstanceState) ;
setContentView(R.layout. activity_main ) ;
Button button = findViewById(R.id. button ) ;
button.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick (View v) {
locationEnabled() ;
}
}) ;
}
private void locationEnabled () {
LocationManager lm = (LocationManager)
getSystemService(Context. LOCATION_SERVICE ) ;
boolean gps_enabled = false;
boolean network_enabled = false;
try {
gps_enabled = lm.isProviderEnabled(LocationManager. GPS_PROVIDER ) ;
} catch (Exception e) {
e.printStackTrace() ;
}
try {
network_enabled = lm.isProviderEnabled(LocationManager. NETWORK_PROVIDER ) ;
} catch (Exception e) {
e.printStackTrace() ;
}
if (!gps_enabled && !network_enabled) {
new AlertDialog.Builder(MainActivity. this )
.setMessage( "GPS Enable" )
.setPositiveButton( "Settings" , new
DialogInterface.OnClickListener() {
@Override
public void onClick (DialogInterface paramDialogInterface , int paramInt) {
startActivity( new Intent(Settings. ACTION_LOCATION_SOURCE_SETTINGS )) ;
}
})
.setNegativeButton( "Cancel" , null )
.show() ;
}
}
} ステップ4 −次のコードをandroidManifest.xmlに追加します
<? xml version= "1.0" encoding= "utf-8" ?> <manifest xmlns: android = "https://schemas.android.com/apk/res/android" package= "app.tutorialspoint.com.sample" > <uses-permission android :name= "android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android :name= "android.permission.ACCESS_COARSE_LOCATION" /> <application android :allowBackup= "true" android :icon= "@mipmap/ic_launcher" android :label= "@string/app_name" android :roundIcon= "@mipmap/ic_launcher_round" android :supportsRtl= "true" android :theme= "@style/AppTheme" > <activity android :name= ".MainActivity" > <intent-filter> <action android :name= "android.intent.action.MAIN" /> <category android :name= "android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
アプリケーションを実行してみましょう。実際のAndroidモバイルデバイスをコンピューターに接続していると思います。 android studioからアプリを実行するには、プロジェクトのアクティビティファイルの1つを開き、ツールバーの[実行]アイコンをクリックします。オプションとしてモバイルデバイスを選択し、デフォルトの画面を表示するモバイルデバイスを確認します–
-
Androidの位置情報を偽造する方法
アプリに位置情報ベースの機能があるAndroid開発者は、機能が正常に機能することを確認するために、スマートフォンの位置情報を偽造または「なりすまし」する必要がある場合があります。開発者以外の人も同じように簡単にこの機能にアクセスできます(Androidの場合、とにかく、iPhoneは少しトリッキーです)。これにより、ジオブロックの回避、アプリのテスト、友達の騙し、政治的および/または企業の監視…あなたの想像力は今限界です!サハラの砂を歩き回ってみませんか?マニトバでムースと一緒に走りますか?タイタニック号に飛び込みますか?このトリックはあなたがそれをするのを助けませんが、それはあなたがあなた
-
Android で GPS 位置情報を偽装する方法
すべての Android デバイスには GPS がサポートされているため、Google マップ、Uber、Facebook、Zomato などのアプリで現在地を追跡できます。 GPS 追跡は、天気、ローカル ニュース、交通状況、近くの場所やイベントに関する情報など、現在地に関連する情報を受け取ることができるため、非常に重要です。党のアプリであり、政府は一部の人にとって非常に威圧的です.また、地域限定のコンテンツへのアクセスも制限されます。たとえば、あなたの国で禁止されている映画を見たい場合、その唯一の方法はあなたの実際の場所を隠すことです. 実際の場所を非表示にして、代わりに偽の場所を使