Множественный приемник намерения близость android
Пожалуйста, помогите мне!!!
Я объявил requestcode = 1 вне GeocoderTask.
Я не знаю, как получить код запроса в непосредственной близости и как с ним справиться.
Я хочу запустить, наконец, Местоположение (Последний код запроса) и другие Места, которые я хочу сделать другие действия
Отправитель отправляю по местам
Мой геокодер
private class GeocoderTask extends AsyncTask<LatLng, Void, List<Address>> {
@Override
protected List<Address> doInBackground(LatLng... locations) {
// Creating an instance of Geocoder class
Geocoder geocoder = new Geocoder(getContext());
List<Address> addresses = null;
try {
addresses = geocoder.getFromLocation(locations[x].latitude, locations[x].longitude, 1);
} catch (IOException e) {
e.printStackTrace();
}
return addresses;
}
@SuppressLint("MissingPermission")
@Override
protected void onPostExecute(List<Address> addresses) {
if (addresses == null || addresses.size() == 0) {
Toast.makeText(getContext(), "No Location found", Toast.LENGTH_SHORT).show();
}
if (addresses != null) {
Toast.makeText(getContext(), "Location found", Toast.LENGTH_SHORT).show();
for (int i = 0; i < addresses.size(); i++) {
Intent intent = new Intent("com.example.a57050358.testboat.util.proximityintentreceiver");
intent.putExtra("RequestCode", requestcode);
Address address = addresses.get(i);
latLng = new LatLng(address.getLatitude(), address.getLongitude());
markerOptions = new MarkerOptions();
markerOptions.position(latLng);
CircleOptions circleOptions = new CircleOptions();
circleOptions.center(latLng);
circleOptions.radius(Rd);
PendingIntent proximityIntent = PendingIntent.getBroadcast(getContext(),requestcode, intent,0 );
locationManager.addProximityAlert(address.getLatitude(), address.getLongitude(), Rd,-1, proximityIntent);
requestcode++;
}
IntentFilter filter = new IntentFilter ("com.example.a57050358.testboat.util.proximityintentreceiver");
getContext().registerReceiver(new ProximityIntentReceiver(), filter);
}
}
}
Моя близость
public class ProximityIntentReceiver extends BroadcastReceiver {
static int NOTIFICATION_ID = 1000 ;
int id = NOTIFICATION_ID;
boolean noti = false;
int short_gap = 200; // Length of Gap Between dots/dashes
int long_gap = 1000; // Length of Gap Between Words
long[] pattern = {
0, long_gap, short_gap, long_gap, short_gap, long_gap
};
private Vibrator vibrate;
@Override
public void onReceive(Context context, Intent intent) {
String key = LocationManager.KEY_PROXIMITY_ENTERING;
Boolean entering = intent.getBooleanExtra(key, false);
String msg;
if (entering) {
Log.d(getClass().getSimpleName(), "entering");
noti = true;
} else {
Log.d(getClass().getSimpleName(), "exiting");
noti = true;
}
final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
final Notification notification = createNotification();
notification.contentIntent = pendingIntent;
notificationManager.notify(NOTIFICATION_ID, notification);
if (id == NOTIFICATION_ID) {
AlertDialog.Builder builder = new AlertDialog.Builder(context, 2);
builder.setTitle(" Alert Me ");
builder.setMessage(" " + "LastLocation" + " ");
builder.setIcon(R.drawable.icn3);
builder.setCancelable(false);
vibrate = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vibrate.vibrate(pattern, 0);
builder.setNegativeButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
notificationManager.notify(NOTIFICATION_ID, notification);
vibrate.cancel();
}
});
builder.show();
id = NOTIFICATION_ID++;
}
private Notification createNotification() {
Notification notification = new Notification();
notification.when = System.currentTimeMillis();
notification.flags |= Notification.FLAG_INSISTENT;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.ledARGB = Color.WHITE;
notification.ledOnMS = 1500;
notification.ledOffMS = 1500;
return notification;
}
}
Спасибо всем за помощь!