通过设备弹出窗口丢失蓝牙连接

时间:2013-08-05 09:35:15

标签: android bluetooth notifications

当我断开与设备的连接时,在创建此弹出窗口时遇到问题。可以有人请求帮助。到目前为止我已经拥有了...

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();
}

0 个答案:

没有答案