当我失去与设备的连接时,在创建此弹出窗口时遇到问题。有人可以帮忙吗。以下是我到目前为止所拥有的。
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) {
NotificationManager nm = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
}
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "This is a warning that you have left your Thumbdrive behind";
long when = System.currentTimeMillis();
CharSequence contentTitle = "WARNING";
CharSequence contentText = "This notification has been generated as a result of BT Disconnecting";
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
/** Initialize the Notification using the above configuration */
final Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
/** Retrieve reference from NotificationManager */
String ns = Context.NOTIFICATION_SERVICE;
final NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
mNotificationManager.notify(NOTIFICATION_ID, notification);
finish();
}