Library that provides a secure data transmission channel between Android devices. It uses QR codes and Bluetooth technologies.
Because data is exchanged via sequences of QR codes, while a Bluetooth channel is used for acknowledgement (ACK) messages only.
- During the transmission, the sender device will act as a Server in a Client-Server architecture, while the receiver will serve as a Client.
- It uses the stop-and-wait protocol.
- It receives an ArrayList<String> as input parameter, containing all the messages to be exchanged. For each String, a new QR code will be created.
- Every exchanged message is checked with a digest (SHA-256).
You can use JitPack to import this library into your project.
Put this into your build.gradle
:
repositories {
maven {
url "https://jitpack.io"
}
}
dependencies {
implementation 'com.github.prgpascal:android-qr-data-transfer:2.0.0'
}
A demo module is available as a working example.
The Server starts the Activity passing an ArrayList<String> as a parameter, containing the messages to be sent:
val intent = Intent(this, ServerTransferActivity::class.java)
val bundle = Bundle()
bundle.putStringArrayList(TransferParams.PARAM_MESSAGES, chunkedTextToTransfer)
intent.putExtras(bundle)
startActivityForResult(intent, DATA_EXCHANGE_REQUEST)
The Client starts the Activity:
val intent = Intent(this, ClientTransferActivity::class.java)
startActivityForResult(intent, DATA_EXCHANGE_REQUEST)
Client and Server can handle the response in the onActivityResult(...) method:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == DATA_EXCHANGE_REQUEST) {
if (resultCode == RESULT_OK) {
val messages: List<String> = data?.getStringArrayListExtra(TransferParams.PARAM_MESSAGES) ?: emptyList()
...
} else {
val error = data?.getStringExtra(TransferParams.PARAM_ERROR)
...
}
}
}
The TransferParams
class provides a set of different responses and errors returned as IntentExtras:
PARAM_I_AM_THE_SERVER
:true
if the device handling the request is the Server,false
otherwise.PARAM_MESSAGES
: List of messages exchanged.PARAM_ERROR
: String representing an error that occurred:ERROR_BT_NOT_AVAILABLE
: if the device doesn't support Bluetooth.ERROR_BT_DISABLED
: if the device has Bluetooth turned off.ERROR_PERMISSIONS_NOT_GRANTED
: if the user didn't grant all the required runtime permissions.ERROR_NO_DEVICE_SELECTED
: if the user did not select a device in the Bluetooth devices list.
android-qr-data-transfer depends on the following external libraries:
- ZXing: used to encode/decode the QR codes.
- ZXing Android Embedded: used to scan sequences of QR codes.
- Others libraries from the Android Support Library.
Copyright 2016 Riccardo Leschiutta
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.