通过通知从服务启动活动,并将结果重新投入使用

时间:2014-04-25 06:18:12

标签: android bluetooth android-service bluetooth-lowenergy

我正在将BLE设备连接到手机,在连接此设备之前我想连接此设备只有当用户从其他活动验证这一点时,我会在找到设备时显示通知并在此页面上启动带验证按钮的活动,直到用户点击on活动上的验证按钮我想在服务中暂停执行onLeScan方法并在验证设备连接后

我的代码是:

   public void onLeScan(final BluetoothDevice device, int rssi,
            byte[] scanRecord) {

        Log.i(TAG, "BluetoothLeService::onLeScan " + device.getAddress()
                + " name: " + device.getName());

  //We are creating notification here

   NotificationManager notificationManager =
                 (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
                Notification myNotification = new Notification(R.drawable.icon,
                  "Notification!",
                  System.currentTimeMillis());
        String notificationTitle = "Exercise of Notification!";
        String notificationText = "http://google.com/";
        Intent myIntent = new Intent(getApplicationContext(), SettingActivity.class);
        PendingIntent pendingIntent
          = PendingIntent.getActivity(getBaseContext(),
            0, myIntent,
            Intent.FLAG_ACTIVITY_NEW_TASK);
        myNotification.defaults |= Notification.DEFAULT_SOUND;
        myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
        myNotification.setLatestEventInfo(getApplicationContext(),
           notificationTitle,
           notificationText,
           pendingIntent);
        notificationManager.notify(0, myNotification);

        if (Verified) {
    if (connect(device.getAddress())) {
    } else {
        //Skip to connect
            }
        }
    }
};

0 个答案:

没有答案