현재 lat, lng 정보가있는 gcm 메시지를받는 IntentService가 있으며 포 그라운드 앱없이 배경에 지오 펜스를 등록하고 싶습니다. 나는 이미 IntentService에 작업 코드를 넣으려고 시도했지만 nullpointerexception을 얻었고 이유는 모른다. 나는이를 수있는 방법을백그라운드에서 충돌없이 백그라운드에서 안드로이드 지오 펜스를 만듭니다.
java.lang.NullPointerException
at com.app.portalalert.GcmIntentService.createGeofences(GcmIntentService.java:142)
at com.app.portalalert.GcmIntentService.onHandleIntent(GcmIntentService.java:85)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.os.HandlerThread.run(HandlerThread.java:61)
어떤 아이디어 나 팁 :
@Override
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
if (!extras.isEmpty()) {
Double lat = Double.parseDouble(extras.getString("lat"));
Double lng = Double.parseDouble(extras.getString("lng"));
Float radius = Float.parseFloat("600");
createGeofences(lat,lng,radius);
}
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
public void createGeofences(Double lat, Double lng, Float radius) {
mRequestType = GeofenceUtils.REQUEST_TYPE.ADD;
SimpleGeofence mGeofence = new SimpleGeofence(
"1",
lat,
lng,
radius,
GEOFENCE_EXPIRATION_IN_MILLISECONDS,
Geofence.GEOFENCE_TRANSITION_ENTER);
// Store this flat version in SharedPreferences
//mPrefs.setGeofence("1", mGeofence);
/*
* Add Geofence objects to a List. toGeofence()
* creates a Location Services Geofence object from a
* flat object
*/
mCurrentGeofences.add(mGeofence.toGeofence());
try {
mGeofenceRequester.addGeofences(mCurrentGeofences);
} catch (UnsupportedOperationException e) {
Toast.makeText(this, R.string.add_geofences_already_requested_error,
Toast.LENGTH_LONG).show();
}
이 오류 메시지는? 이 같은
라인에 무엇이'GcmIntentService.java : 142'? – donfuxx
mCurrentGeofences.add (mGeofence.toGeofence()); – Lorof
어디에서'mCurrentGeofences'를 초기화 했습니까? – donfuxx