private void startProbeOrDongleActivity() { // Restart the Probe or Dongle from here: final Intent intent; SentekBluetoothDevice deviceOld = SentekApplication.mdevice; if (deviceOld == null) { deviceOld = mbluetoothLeDevice; } if (mBleDeviceType == SentekBLEDeviceType.Dongle_DFU.ordinal() && mFileType == DfuService.TYPE_APPLICATION) { intent = new Intent(this, DongleActivity.class); intent.putExtra(DongleActivity.EXTRA_DEVICE, deviceOld); intent.putExtra(ProbeActivity.EXTRA_PAIRED_DEVICE, Boolean.FALSE); intent.putExtra(ProbeActivity.EXTRA_BLE_DEVICE_TYPE, SentekBLEDeviceType.DONGLE.ordinal()); startActivity(intent); // Finish does call the onDestroy finish(); this.finishAffinity(); } else if (mBleDeviceType == SentekBLEDeviceType.Probe_DFU.ordinal() && mFileType == DfuService.TYPE_APPLICATION) { intent = new Intent(this, ProbeActivity.class); intent.putExtra(ProbeActivity.EXTRA_DEVICE, deviceOld); intent.putExtra(ProbeActivity.EXTRA_PAIRED_DEVICE, Boolean.FALSE); intent.putExtra(ProbeActivity.EXTRA_BLE_DEVICE_TYPE, SentekBLEDeviceType.PROBE.ordinal()); startActivity(intent); // Finish does call the onDestroy finish(); this.finishAffinity(); } }
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_feature_dfu); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); isBLESupported(); setGUI(); // Try to create sample files if (FileHelper.newSamplesAvailable(this)) { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { FileHelper.createSamples(this); } else { final DialogFragment dialog = PermissionRationaleFragment.getInstance( R.string.permission_sd_text, Manifest.permission.WRITE_EXTERNAL_STORAGE); dialog.show(getSupportFragmentManager(), null); } } // restore saved state mFileType = DfuService.TYPE_AUTO; // Default if (savedInstanceState != null) { mFileType = savedInstanceState.getInt(DATA_FILE_TYPE); mFileTypeTmp = savedInstanceState.getInt(DATA_FILE_TYPE_TMP); mFilePath = savedInstanceState.getString(DATA_FILE_PATH); mFileStreamUri = savedInstanceState.getParcelable(DATA_FILE_STREAM); mInitFilePath = savedInstanceState.getString(DATA_INIT_FILE_PATH); mInitFileStreamUri = savedInstanceState.getParcelable(DATA_INIT_FILE_STREAM); mSelectedDevice = savedInstanceState.getParcelable(DATA_DEVICE); mStatusOk = mStatusOk || savedInstanceState.getBoolean(DATA_STATUS); mUploadButton.setEnabled(mSelectedDevice != null && mStatusOk); } final Intent intent = getIntent(); mbluetoothLeDevice = intent.getParcelableExtra(BLEDeviceActivity.EXTRA_DEVICE); mBleDeviceType = intent.getIntExtra(BLEDeviceActivity.EXTRA_BLE_DEVICE_TYPE, 0xff); if (mBleDeviceType == SentekBLEDeviceType.Dongle_DFU.ordinal()) { swapDFU_UUID(true); } else if (mBleDeviceType == SentekBLEDeviceType.Probe_DFU.ordinal()) { swapDFU_UUID(false); } if (mbluetoothLeDevice != null) { mSelectedDevice = mbluetoothLeDevice.getDevice(); mUploadButton.setEnabled(mStatusOk); mDeviceNameView.setText( mSelectedDevice.getName() != null ? mSelectedDevice.getName() : getString(R.string.sentek_dfu)); } FileHelper.createSamplesNew(this); mFileType = mFileTypeTmp = DfuService.TYPE_APPLICATION; updateFileInfoNew(false); // TODO: // doUpload(true); }
private String getDATfileName(int mFileType) { switch (mFileType) { case DfuService.TYPE_SOFT_DEVICE: return FileHelper.SOFTDEVICE_DAT; case DfuService.TYPE_BOOTLOADER: return FileHelper.BOOTLOADER_DAT; case DfuService.TYPE_APPLICATION: if (mBleDeviceType == SentekBLEDeviceType.Dongle_DFU.ordinal()) { return FileHelper.DONGLE_DAT; } else if (mBleDeviceType == SentekBLEDeviceType.Probe_DFU.ordinal()) { return FileHelper.PROBE_DAT; } } return "Test"; }