0
私はBroadcastReceiverクラスにsmsトリガーをチェックし、起動されたトリガーに基づいて関数を実行するメソッドを持っています。これは、smsの内容をフィルタリングし、msgを返信して応答のSMSを送信する方法です。BroadcastReceiverクラスでGPS座標を取得する方法
私は現在、「ロケータ」条件でlocationListenerをNetwork/GPSに登録する条件を持っています。しかし、座標の正しいデータシークの前に空の内容の "msg"を返しています。
私はwhileループを試しましたが、私はそれを不安定にしました。無限ループと思われます。 startActivityResultも試しましたが、できませんでした。
アドバイスをしてください。
public String methodTrigger(Context context, String operation){
String returnMsg="";
if (operation.equalsIgnoreCase("Lock")){
Intent lock = new Intent(context, lockscreen.class);
lock.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(lock);
returnMsg = "Lock Operation Enabled";
}else if(operation.equalsIgnoreCase("Locate")){
String msg = "";
Log.i("monitor", "Create");
LocationManager lm = (LocationManager) context.getSystemService(context.LOCATION_SERVICE);
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
int lat = (int) (location.getLatitude() * 1E6);
int lng = (int) (location.getLongitude() * 1E6);
test = "Latitude: "+String.valueOf(lat)+"\nLongitude: "+String.valueOf(lng);
Log.i("monitor", "Reading coordintes");
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
// Register the listener with the Location Manager to receive location updates
if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)){
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
Log.i("monitor", "Listen Network");
}else{
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
Log.i("monitor", "Listen GPS");
}
Log.i("monitor", "Finish");
returnMsg = test;
}else if(...other functions.....
}
return returnMsg;
}