0
집, 사무실 및 놀이터와 같은 세 위치를 고려하십시오. 해당 위치로 들어가고 나올 때마다 메시지 경고가 표시됩니다. 이 MainActivity.java 내가 여러 근접 점 를 추가 내 주요 활동이다브로드 캐스트 리시버를 사용하여 근접 알림을 여러 개 설정하십시오. android
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
latitudeEditText = (EditText) findViewById(R.id.point_latitude);
longitudeEditText = (EditText) findViewById(R.id.point_longitude);
addAlertButton = (Button) findViewById(R.id.add_alert_button);
double latitude = 43.039, latitude1 = 43.039;
double longitude = 60.238, longitude1 = 60.239;
addProximityAlert(latitude, longitude);
addProximityAlert(latitude1, longitude1);
Toast.makeText(getApplicationContext(), "Alert Added", Toast.LENGTH_SHORT).show();
}
private void addProximityAlert(double latitude,double longitude) {
Intent intent = new Intent(PROX_ALERT_INTENT);
intent.putExtra("lat",latitude);
intent.putExtra("long",longitude);
PendingIntent proximityIntent = PendingIntent.getBroadcast(this, (int) System.currentTimeMillis(), intent,PendingIntent.FLAG_CANCEL_CURRENT);
Toast.makeText(this,Long.toString(System.currentTimeMillis()),Toast.LENGTH_LONG).show();
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
locationManager.addProximityAlert(latitude,
longitude,
POINT_RADIUS,
PROX_ALERT_EXPIRATION,
proximityIntent
);
IntentFilter filter = new IntentFilter(PROX_ALERT_INTENT);
registerReceiver(new ProximityIntentReceiver(), filter);
}
//이 내가
public class ProximityIntentReceiver extends BroadcastReceiver {
private static final int NOTIFICATION_ID = 1000;
double lat,lng;
String d="";
@Override
public void onReceive(Context context, Intent intent) {
String key = LocationManager.KEY_PROXIMITY_ENTERING;
Boolean entering = intent.getBooleanExtra(key, false);
lat=intent.getDoubleExtra("lat",0.00);
lng=intent.getDoubleExtra("long",0.00);
if (entering) {
Log.d(getClass().getSimpleName(), "entering");
d="Entering region"+Double.toString(lat)+Double.toString(lng);
Toast.makeText(context, d, Toast.LENGTH_SHORT).show();
}else {
Log.d(getClass().getSimpleName(), "exiting");
d= "Exiting region"+Double.toString(lat)+Double.toString(lng);
Toast.makeText(context,d, Toast.LENGTH_SHORT).show();
}
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, (int) System.currentTimeMillis(), notificationIntent, 0);
Notification n = new Notification.Builder(context)
.setContentTitle("Proximity")
.setContentText("Subject: "+d)
.setSmallIcon(R.drawable.hell)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.build();
notificationManager.notify((int) System.currentTimeMillis(), n);
}
}
PendingIntentReceiver.java를 입력하고 기존 경고
통지 내 대기 의도 수신기
그래서 whats 무엇 귀하의 질문은? – Arjun
나는 그것을위한 코드가 필요하다 !! – Senthil
그리고 왜 우리는 당신을 위해 코드 할 시간이 있다고 생각합니까? !!!!! – Arjun