private int mActiveNotificationId = 0;
- private Notification mOutNoti = null;
-
- private Notification mInNoti = null;
-
/**
* This inner class is used to describe some properties for one transfer.
*/
outboundNum = outboundSuccNumber + outboundFailNumber;
// create the outbound notification
if (outboundNum > 0) {
- mOutNoti = new Notification();
- mOutNoti.icon = android.R.drawable.stat_sys_upload_done;
+ Notification outNoti = new Notification();
+ outNoti.icon = android.R.drawable.stat_sys_upload_done;
title = mContext.getString(R.string.outbound_noti_title);
caption = mContext.getString(R.string.noti_caption, outboundSuccNumber,
outboundFailNumber);
intent = new Intent(Constants.ACTION_OPEN_OUTBOUND_TRANSFER);
intent.setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName());
- mOutNoti.setLatestEventInfo(mContext, title, caption, PendingIntent.getBroadcast(
+ outNoti.setLatestEventInfo(mContext, title, caption, PendingIntent.getBroadcast(
mContext, 0, intent, 0));
- mOutNoti.when = timeStamp;
- mNotificationMgr.notify(NOTIFICATION_ID_OUTBOUND, mOutNoti);
+ outNoti.when = timeStamp;
+ mNotificationMgr.notify(NOTIFICATION_ID_OUTBOUND, outNoti);
} else {
- if (mNotificationMgr != null && mOutNoti != null) {
+ if (mNotificationMgr != null) {
mNotificationMgr.cancel(NOTIFICATION_ID_OUTBOUND);
- mOutNoti = null;
if (V) Log.v(TAG, "outbound notification was removed.");
}
}
inboundNum = inboundSuccNumber + inboundFailNumber;
// create the inbound notification
if (inboundNum > 0) {
- mInNoti = new Notification();
- mInNoti.icon = android.R.drawable.stat_sys_download_done;
+ Notification inNoti = new Notification();
+ inNoti.icon = android.R.drawable.stat_sys_download_done;
title = mContext.getString(R.string.inbound_noti_title);
caption = mContext.getString(R.string.noti_caption, inboundSuccNumber,
inboundFailNumber);
intent = new Intent(Constants.ACTION_OPEN_INBOUND_TRANSFER);
intent.setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName());
- mInNoti.setLatestEventInfo(mContext, title, caption, PendingIntent.getBroadcast(
+ inNoti.setLatestEventInfo(mContext, title, caption, PendingIntent.getBroadcast(
mContext, 0, intent, 0));
- mInNoti.when = timeStamp;
- mNotificationMgr.notify(NOTIFICATION_ID_INBOUND, mInNoti);
+ inNoti.when = timeStamp;
+ mNotificationMgr.notify(NOTIFICATION_ID_INBOUND, inNoti);
} else {
- if (mNotificationMgr != null && mInNoti != null) {
+ if (mNotificationMgr != null) {
mNotificationMgr.cancel(NOTIFICATION_ID_INBOUND);
- mInNoti = null;
if (V) Log.v(TAG, "inbound notification was removed.");
}
}
import android.app.Activity;
import android.app.AlertDialog;
+import android.bluetooth.BluetoothAdapter;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
private int mContextMenuPosition;
+ /** Class to handle Notification Manager updates */
+ private BluetoothOppNotification mNotifier;
+
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mListView.setOnCreateContextMenuListener(this);
mListView.setOnItemClickListener(this);
}
+
+ mNotifier = new BluetoothOppNotification(this);
}
@Override
switch (item.getItemId()) {
case R.id.transfer_menu_open:
openCompleteTransfer();
+ updateNotificationWhenBtDisabled();
return true;
case R.id.transfer_menu_clear:
int sessionId = mTransferCursor.getInt(mIdColumnId);
Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + sessionId);
BluetoothOppUtility.updateVisibilityToHidden(this, contentUri);
+ updateNotificationWhenBtDisabled();
return true;
}
return false;
mTransferCursor.moveToNext();
}
+ updateNotificationWhenBtDisabled();
}
}
// Open the selected item
mTransferCursor.moveToPosition(position);
openCompleteTransfer();
+ updateNotificationWhenBtDisabled();
}
/**
this.startActivity(in);
}
}
+
+ /**
+ * When Bluetooth is disabled, notification can not be updated by
+ * ContentObserver in OppService, so need update manually.
+ */
+ private void updateNotificationWhenBtDisabled() {
+ BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+ if (!adapter.isEnabled()) {
+ if (V) Log.v(TAG, "Bluetooth is not enabled, update notification manually.");
+ mNotifier.updateNotification();
+ mNotifier.finishNotification();
+ }
+ }
}