[android] activate the ConnectivityReceiver when starting the download
This commit is contained in:
committed by
Łukasz Paczos
parent
8c5c4dd565
commit
51daaa1e3c
@@ -1,13 +1,16 @@
|
||||
package com.mapbox.mapboxsdk.offline;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.Keep;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.mapbox.mapboxsdk.LibraryLoader;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.net.ConnectivityReceiver;
|
||||
import com.mapbox.mapboxsdk.storage.FileSource;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -30,6 +33,9 @@ public class OfflineRegion {
|
||||
|
||||
// Members
|
||||
|
||||
// Application context
|
||||
private final Context context;
|
||||
|
||||
// Holds the pointer to JNI OfflineRegion
|
||||
@Keep
|
||||
private long nativePtr;
|
||||
@@ -223,6 +229,7 @@ public class OfflineRegion {
|
||||
@Keep
|
||||
private OfflineRegion(long offlineRegionPtr, FileSource fileSource, long id,
|
||||
OfflineRegionDefinition definition, byte[] metadata) {
|
||||
this.context = Mapbox.getApplicationContext();
|
||||
this.fileSource = fileSource;
|
||||
this.id = id;
|
||||
this.definition = definition;
|
||||
@@ -307,9 +314,11 @@ public class OfflineRegion {
|
||||
*/
|
||||
public void setDownloadState(@DownloadState int state) {
|
||||
if (state == STATE_ACTIVE) {
|
||||
ConnectivityReceiver.instance(context).activate();
|
||||
fileSource.activate();
|
||||
} else {
|
||||
fileSource.deactivate();
|
||||
ConnectivityReceiver.instance(context).deactivate();
|
||||
}
|
||||
|
||||
this.state = state;
|
||||
|
||||
Reference in New Issue
Block a user