저는 Android 용 지오 펜스 앱을 개발 중입니다. Google에서 제공하는 example의 도움으로 IntentService
에서 BroadcastReceiver
으로 리팩토링하면 here으로 표시됩니다. 앱이 백그라운드에있는 경우 예상대로 작동하는 앱을 보유하게되었습니다. 내가 관리하지 못한 것은 내 앱을 업데이트 할 수있는 방법입니다. 앱이 죽으면 모델이 될까요? 내 GeofenceReceiver
은 앱이 죽는 동안 트리거되거나 호출되지만 내 MainActivity
에는 내 BroadcastReceiver
메시지가 수신되지 않습니다. 내 GeofenceReceiver
에서IntentReceiver에서 닫힌/종료 된 앱을 업데이트하는 방법은 무엇입니까?
나는 지오 펜스 전이 얻는 경우에 나는 같은 것을 할 : 이미 방송이 수신되는 것을 특징으로
Intent broadcastIntent = new Intent(ACTION);
broadcastIntent.putExtra("resultCode", Activity.RESULT_OK);
broadcastIntent.putExtra(Constants.BUNDLE_KEY, bundle);
LocalBroadcastManager.getInstance(context).sendBroadcast(broadcastIntent);
:
1 :
Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.putStringArrayListExtra(Constants.TRIGGERING_GEOFENCE_IDS_KEY, triggeringIDs);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(notificationIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
.setColor(Color.RED)
.setContentTitle(notificationDetails)
.setContentText(context.getString(R.string.geofence_transition_notification_text))
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentIntent(resultPendingIntent);
builder.setAutoCancel(true);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, builder.build());
(2) 내 MainActivity
에 앱이 백그라운드에있는 경우 앱을 죽이면 내 MainActivity
에 방송이 수신되지 않습니다. 터미널과 logcat으로 확인했습니다.
아이디어가 있으십니까?
그래서 당신은 당신이 당신의 브로드 캐스트 리시버에 방송을 받게되는 것을 의미하지만, 당신이 당신의 주요 활동 안에 그것을 얻을하지 않습니다 무엇? – cafebabe1991
@ cafebabe1991 기본적으로 그렇습니다. 내 GeofenceReceiver 여전히 응용 프로그램이 사망하더라도 지오 펜스 전환을 요구하고 있지만 그때 내 MainActivity에 뭔가를 방송 할 수 없습니다. – wman