1
ユーザーが近くに来たときに通知を開始するコードを作成しようとしています。私はその話題についてグーグルでは、解決策を見つけることができませんでした。私は次のコードを使用していますが、それは動作していません。場所の近くで通知を生成する
次のコードは、その内部クラス=から
`@Override ます。public void onLocationChanged(所在地LOC)
{
たCharSequence LocationListenerを実装MyLocationListenerである私の場所のクラスである "AlarmManager! - 時間のアップ" ;
CharSequence message = "これはあなたの警告です";
loc.getLatitude();
loc.getLongitude();
String Text = "My current location is: " +
"Latitud = " + loc.getLatitude() +
"Longitud = " + loc.getLongitude();
float radius = 500; //Distance in meters
Location location1 = new Location("GPS");
location1.setLatitude(loc.getLatitude());
location1.setLongitude(location1.getLongitude());
Location location2 = new Location("GPS");
location2.setLatitude(22.727739);
location2.setLongitude(75.886074);
Float distance = location1.distanceTo(location2);
distance = Math.abs(distance);
if(distance < radius)
{
Log.d("sdsd", "task location");
notMan = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification n = new Notification(R.drawable.ic_launcher, "Click here for details", System.currentTimeMillis());
Intent notificationIntent = new Intent(Location_Gps.this,Location_Gps.class);
PendingIntent pendingIntent = PendingIntent.getActivity(Location_Gps.this, 0, notificationIntent, 0);
n.setLatestEventInfo(Location_Gps.this, from,message, pendingIntent);
notMan.notify(10001, n);
}
Toast.makeText(getApplicationContext(), Text, Toast.LENGTH_SHORT).show();
}
トピックに関するご意見はありがとうございます。
これはサービス内で実行されますか? –
いいえサービス内で実行されていません – Shubhanshu