Merge pull request #8 from hrldcpr/release
ability to disable the progress notification in the status bar
This commit is contained in:
commit
327c96d17a
|
@ -106,6 +106,10 @@ public abstract class DfuBaseService extends IntentService {
|
||||||
* The optional device name. This name will be shown in the notification.
|
* The optional device name. This name will be shown in the notification.
|
||||||
*/
|
*/
|
||||||
public static final String EXTRA_DEVICE_NAME = "no.nordicsemi.android.dfu.extra.EXTRA_DEVICE_NAME";
|
public static final String EXTRA_DEVICE_NAME = "no.nordicsemi.android.dfu.extra.EXTRA_DEVICE_NAME";
|
||||||
|
/**
|
||||||
|
* A boolean indicating whether to disable the progress notification in the status bar. Defaults to false.
|
||||||
|
*/
|
||||||
|
public static final String EXTRA_DISABLE_NOTIFICATION = "no.nordicsemi.android.dfu.extra.EXTRA_DISABLE_NOTIFICATION";
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* If the new firmware (application) does not share the bond information with the old one, the bond information is lost. Set this flag to <code>true</code>
|
* If the new firmware (application) does not share the bond information with the old one, the bond information is lost. Set this flag to <code>true</code>
|
||||||
|
@ -543,6 +547,7 @@ public abstract class DfuBaseService extends IntentService {
|
||||||
private InputStream mInputStream;
|
private InputStream mInputStream;
|
||||||
private String mDeviceAddress;
|
private String mDeviceAddress;
|
||||||
private String mDeviceName;
|
private String mDeviceName;
|
||||||
|
private boolean mDisableNotification;
|
||||||
/**
|
/**
|
||||||
* The current connection state. If its value is > 0 than an error has occurred. Error number is a negative value of mConnectionState
|
* The current connection state. If its value is > 0 than an error has occurred. Error number is a negative value of mConnectionState
|
||||||
*/
|
*/
|
||||||
|
@ -1075,6 +1080,7 @@ public abstract class DfuBaseService extends IntentService {
|
||||||
// Read input parameters
|
// Read input parameters
|
||||||
final String deviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS);
|
final String deviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS);
|
||||||
final String deviceName = intent.getStringExtra(EXTRA_DEVICE_NAME);
|
final String deviceName = intent.getStringExtra(EXTRA_DEVICE_NAME);
|
||||||
|
final boolean disableNotification = intent.getBooleanExtra(EXTRA_DISABLE_NOTIFICATION, false);
|
||||||
final String filePath = intent.getStringExtra(EXTRA_FILE_PATH);
|
final String filePath = intent.getStringExtra(EXTRA_FILE_PATH);
|
||||||
final Uri fileUri = intent.getParcelableExtra(EXTRA_FILE_URI);
|
final Uri fileUri = intent.getParcelableExtra(EXTRA_FILE_URI);
|
||||||
final int fileResId = intent.getIntExtra(EXTRA_FILE_RES_ID, 0);
|
final int fileResId = intent.getIntExtra(EXTRA_FILE_RES_ID, 0);
|
||||||
|
@ -1105,6 +1111,7 @@ public abstract class DfuBaseService extends IntentService {
|
||||||
|
|
||||||
mDeviceAddress = deviceAddress;
|
mDeviceAddress = deviceAddress;
|
||||||
mDeviceName = deviceName;
|
mDeviceName = deviceName;
|
||||||
|
mDisableNotification = disableNotification;
|
||||||
mConnectionState = STATE_DISCONNECTED;
|
mConnectionState = STATE_DISCONNECTED;
|
||||||
mBytesSent = 0;
|
mBytesSent = 0;
|
||||||
mBytesConfirmed = 0;
|
mBytesConfirmed = 0;
|
||||||
|
@ -2675,6 +2682,16 @@ public abstract class DfuBaseService extends IntentService {
|
||||||
* {@link #PROGRESS_VALIDATING}, {@link #PROGRESS_DISCONNECTING}, {@link #PROGRESS_COMPLETED} or {@link #ERROR_FILE_ERROR}, {@link #ERROR_FILE_INVALID} , etc
|
* {@link #PROGRESS_VALIDATING}, {@link #PROGRESS_DISCONNECTING}, {@link #PROGRESS_COMPLETED} or {@link #ERROR_FILE_ERROR}, {@link #ERROR_FILE_INVALID} , etc
|
||||||
*/
|
*/
|
||||||
private void updateProgressNotification(final int progress) {
|
private void updateProgressNotification(final int progress) {
|
||||||
|
|
||||||
|
// send progress or error broadcast
|
||||||
|
if (progress < ERROR_MASK)
|
||||||
|
sendProgressBroadcast(progress);
|
||||||
|
else
|
||||||
|
sendErrorBroadcast(progress);
|
||||||
|
|
||||||
|
if (mDisableNotification) return;
|
||||||
|
// create or update notification:
|
||||||
|
|
||||||
final String deviceAddress = mDeviceAddress;
|
final String deviceAddress = mDeviceAddress;
|
||||||
final String deviceName = mDeviceName != null ? mDeviceName : getString(R.string.dfu_unknown_name);
|
final String deviceName = mDeviceName != null ? mDeviceName : getString(R.string.dfu_unknown_name);
|
||||||
|
|
||||||
|
@ -2722,11 +2739,6 @@ public abstract class DfuBaseService extends IntentService {
|
||||||
builder.setOngoing(true).setContentTitle(title).setContentText(text).setProgress(100, progress, false);
|
builder.setOngoing(true).setContentTitle(title).setContentText(text).setProgress(100, progress, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// send progress or error broadcast
|
|
||||||
if (progress < ERROR_MASK)
|
|
||||||
sendProgressBroadcast(progress);
|
|
||||||
else
|
|
||||||
sendErrorBroadcast(progress);
|
|
||||||
|
|
||||||
// update the notification
|
// update the notification
|
||||||
final Intent intent = new Intent(this, getNotificationTarget());
|
final Intent intent = new Intent(this, getNotificationTarget());
|
||||||
|
|
|
@ -38,6 +38,8 @@ public class DfuServiceInitiator {
|
||||||
private final String deviceAddress;
|
private final String deviceAddress;
|
||||||
private String deviceName;
|
private String deviceName;
|
||||||
|
|
||||||
|
private boolean disableNotification;
|
||||||
|
|
||||||
private Uri fileUri;
|
private Uri fileUri;
|
||||||
private String filePath;
|
private String filePath;
|
||||||
private int fileResId;
|
private int fileResId;
|
||||||
|
@ -71,6 +73,17 @@ public class DfuServiceInitiator {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether the progress notification in the status bar should be disabled.
|
||||||
|
* Defaults to false.
|
||||||
|
* @param disableNotification whether to disable the notification
|
||||||
|
* @return the builder
|
||||||
|
*/
|
||||||
|
public DfuServiceInitiator setDisableNotification(final boolean disableNotification) {
|
||||||
|
this.disableNotification = disableNotification;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether the bond information should be preserver after flashing new application. This feature requires DFU Bootloader version 0.6 or newer (SDK 8.0.0+).
|
* Sets whether the bond information should be preserver after flashing new application. This feature requires DFU Bootloader version 0.6 or newer (SDK 8.0.0+).
|
||||||
* Please see the {@link DfuBaseService#EXTRA_KEEP_BOND} for more information regarding requirements. Remember that currently updating the Soft Device will remove the bond information.
|
* Please see the {@link DfuBaseService#EXTRA_KEEP_BOND} for more information regarding requirements. Remember that currently updating the Soft Device will remove the bond information.
|
||||||
|
@ -245,6 +258,7 @@ public class DfuServiceInitiator {
|
||||||
|
|
||||||
intent.putExtra(DfuBaseService.EXTRA_DEVICE_ADDRESS, deviceAddress);
|
intent.putExtra(DfuBaseService.EXTRA_DEVICE_ADDRESS, deviceAddress);
|
||||||
intent.putExtra(DfuBaseService.EXTRA_DEVICE_NAME, deviceName);
|
intent.putExtra(DfuBaseService.EXTRA_DEVICE_NAME, deviceName);
|
||||||
|
intent.putExtra(DfuBaseService.EXTRA_DISABLE_NOTIFICATION, disableNotification);
|
||||||
intent.putExtra(DfuBaseService.EXTRA_FILE_MIME_TYPE, mimeType);
|
intent.putExtra(DfuBaseService.EXTRA_FILE_MIME_TYPE, mimeType);
|
||||||
intent.putExtra(DfuBaseService.EXTRA_FILE_TYPE, fileType);
|
intent.putExtra(DfuBaseService.EXTRA_FILE_TYPE, fileType);
|
||||||
intent.putExtra(DfuBaseService.EXTRA_FILE_URI, fileUri);
|
intent.putExtra(DfuBaseService.EXTRA_FILE_URI, fileUri);
|
||||||
|
|
Loading…
Reference in New Issue