@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); }
@Override public void onRequestPermissionsResult( final int requestCode, final String[] permissions, final int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case PERMISSION_REQ: { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { // We have been granted the Manifest.permission.WRITE_EXTERNAL_STORAGE permission. Now // we may proceed with exporting. FileHelper.createSamples(this); } else { Toast.makeText(this, R.string.no_required_permission, Toast.LENGTH_SHORT).show(); } break; } } }