How to change Bluetooth storage location in Android? - android

I have an application. It is used to send and receive files using Bluetooth. My problem is, i wish to change the default location to store the file using Bluetooth at runtime. Can you tell me, Is there any possibility for this case?

It's not possible to configure it up to Android 4.1 Jelly Bean:
With the included stock bluetooth receiver you cannot change the location as of now, because it's hard coded. You need a 3rd party app like Bluetooth file transfer which might be configurable here.
In ./packages/apps/Bluetooth/src/com/android/bluetooth/opp/ you can see it.
Constants.java defines this:
public static final String DEFAULT_STORE_SUBDIR = "/bluetooth";
BluetoothOppReceiveFileInfo.java has no switch for the location:
File receiveFile = new File(uniqueFileName);
if (sDesiredStoragePath == null) {
sDesiredStoragePath = Environment.getExternalStorageDirectory().getPath() +
Constants.DEFAULT_STORE_SUBDIR;
}

Related

NFC-tag password protection with ST25 android SDK

I'm working with ST25 tags, more specifically type5 tags ST25DV64K. The ST25 SDK for android has some interesting examples and tutorials in it. I'm still struggling to use the code example provided at the end of the doc here concerning password-protected data, which consist in those lines:
byte[] password;
int passwordNumber = type5Tag.getPasswordNumber(area);
tag.presentPassword(passwordNumber, password);
NDEFMsg ndefMsg = myTag.readNdefMessage(area);
first problem, when I instanciate a type5 tag i don't see those methods for Type5Tag class:
import com.st.st25sdk.type5.*;
Type5Tag tag5;
tag5.??
Then, it is not clear how we are supposed to set up a password in the first place. I can't find any examples of setting up a password for a specific area, and removing it, and what is the format of the password that we can use? Is it possible to do this from android or do we have to use the ST25 app? Examples welcome! Thanks.
In the ST25 SDK Zip file, you will find an example of a basic Android App using the ST25 SDK Library (it is in \integration\android\examples\ST25AndroidDemoApp).
This example uses a class called “TagDiscovery” which is able to identify any ST25 Tag and to instantiate the right object. In your case, if you are only using ST25DV64K Tags, you will probably want to do something simple.
Here is what I suggest you:
In your android activity, I expect that you have subscribed to receive a notification every time an NFC tag is taped (in “ST25AndroidDemoApp” example, look at enableForegroundDispatch() in onResume() function).
To identify if the Intent corresponds to an “NFC Intent”, we check if the Intent’s Action is ACTION_NDEF_DISCOVERED, or ACTION_TECH_DISCOVERED or ACTION_TAG_DISCOVERED.
When this is the case, we know that it is an NFC Intent. We can then call this to get the instance of androidTag:
Tag androidTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
This object represents the current NFC tag in Android.
We’re now going to instantiate a ST25DVTag object.
import com.st.st25sdk.type5.st25dv.ST25DVTag;
…
AndroidReaderInterface readerInterface = AndroidReaderInterface.newInstance(androidTag);
byte[] uid = androidTag.getId();
uid = Helper.reverseByteArray(uid);
ST25DVTag myST25DVTag = new ST25DVTag(readerInterface, uid);
You now have an object called myST25DVTag that can be used to communicate with the tag!
For example, if you want to use the passwords:
byte[] password = new byte[]; // TODO: Fill the password
int passwordNumber = myST25DVTag.getPasswordNumber(area);
myST25DVTag.presentPassword(passwordNumber, password);
NDEFMsg ndefMsg = myST25DVTag.readNdefMessage(area);
Before doing that, you need to check which password is associated to this area. The tag has 3 passwords that can be freely assigned to any area. By default no password is set so you should set one. Here is an example where I use the password 2 for Area1:
int AREA1 = 1;
int passwordChosen = 2;
myST25DVTag.setPasswordNumber(AREA1, passwordChosen);
I suggest that you install the ”ST25 NFC Tap” Android App from Google Play: https://play.google.com/store/apps/details?id=com.st.st25nfc&hl=fr&gl=US
If you tap you ST25DV and go to the “Areas Security Status” menu, you will be able to see: the number of areas, which ones are protected by password for read and/or write, which password is used…etc
If you are interested, the source code of this application is available here: https://www.st.com/en/embedded-software/stsw-st25001.html
Tell me if something is unclear.
Disclaimer: I am on of the development team for the ST25 SDK.

How to enable Android Open Application voice interaction

According to the system voice command docs, you can open an application with a voice command. e.g. OK Google - open foobar. Also according to the docs, this Works by default; no specific intent.
In my sample development app, this isn't working. I've tried adding a few combinations of action and category permutations to the intent-filter, but no luck so far.
I'm targeting a minimum SDK of 23, testing on a device with 6.0.1.
Should this work, and if so, what are the changes to a new empty activity project I need to enable it?
As far as I am aware, Google simply iterates over a list of installed applications and opens the corresponding application if it finds an exact match.
To test this, use the following Intent
final String PACKAGE_NAME_GOOGLE_NOW = "com.google.android.googlequicksearchbox";
final String GOOGLE_NOW_SEARCH_ACTIVITY = ".SearchActivity";
final String APP_NAME = "Open " +getString(R.string.app_name);
final Intent startMyAppIntent = new Intent(Intent.ACTION_WEB_SEARCH);
startMyAppIntent.setComponent(new ComponentName(PACKAGE_NAME_GOOGLE_NOW,
PACKAGE_NAME_GOOGLE_NOW + GOOGLE_NOW_SEARCH_ACTIVITY));
startMyAppIntent.putExtra(SearchManager.QUERY, APP_NAME);
startMyAppIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(startMyAppIntent);
} catch (final ActivityNotFoundException e) {
e.printStackTrace();
}
If this opens your application, then it is simply a case of the phonetics of your application name, or how Google interprets your pronunciation of it.
I do think that there should be an option to add a 'phonetic app label' to the application's manifest (or some other globally available configuration file), so Google could open your application if the unique name is not common enough to generate a voice search result.
If this doesn't open your application, check that you are correctly defining your application name in the manifest as follows:
<application
android:label="#string/app_name"

How to change the connected BLE device name in Android programatically?

In my android application, BLE connection is working successfully, once BLE device has been connected to Android phone. How to change the connected BLE device name programatically? Sample code like below
private static final UUID Device_Name_UUID = UUID.fromString("00002a00-0000-1000-8000-00805f9b34fb");
private static final UUID Write_UUID = UUID.fromString("00001800-0000-1000-8000-00805f9b34fb");
public void Device_Name(){
BluetoothGattService Name_Service = mBluetoothGatt.getService(Write_UUID );
if(Name_Service == null) {
Log.d(TAG, "Name_Service service not found!");
return;
}
BluetoothGattCharacteristic DeviceName = Name_Service.getCharacteristic(Device_Name_UUID);
if(DeviceName == null) {
Log.d(TAG, "DeviceName charateristic not found!");
return;
}
}
Log.v(TAG, "readCharacteristic(DeviceName) = " + mBluetoothGatt.readCharacteristic(DeviceName));
String i = "123";
DeviceName.setValue(i);
Log.v(TAG, "writeCharacteristic(DeviceName) = " + mBluetoothGatt.writeCharacteristic(DeviceName));
Log.v(TAG, "writeCharacteristic(DeviceName) = " + mBluetoothGatt.writeCharacteristic(DeviceName));
Here mBluetoothGatt.writeCharacteristic(DeviceName); method always returns false.
After some Research I found Below solution
You need to modify the firmware of CC2541 keyfob to add the write permission of device name by adding the code below into KeyFobApp_Init() inside keyfobdemo.c:
uint8 devNamePermission = GATT_PERMIT_READ|GATT_PERMIT_WRITE;
GGS_SetParameter( GGS_W_PERMIT_DEVICE_NAME_ATT, sizeof ( uint8 ), &devNamePermission );
Now my question is, where we need to add these permissions?
Please can anybody tell me that how to add these persmissions?
Thanks in advance
As the name indicates: keyfobdemo.c is a .c file, so TI is telling you that you have to add those permissions in the KeyFobDemo workspace, so you have to program the CC2541 kit in order to change the name. You cannot do it in Android.
All you have to do is:
Download the BLE stack from Texas Instruments website:
http://www.ti.com/tool/ble-stack
Then in the stack, open Projects\ble\KeyFob\CC2541DB\KeyFobDemo.eww file.
Programming of CC2540 kit requires an IDE named IAR Embedded Workbench. You can download it and get access with 30-days trial:
http://www.iar.com/Products/IAR-Embedded-Workbench/8051/
Then open the project and find the keyfobdemo.c file in the APP folder. From line 200-213 there is a char array named deviceName[], which actually defines the advertising name as "Keyfobdemo". You just have to change that to the desired name with correct hex values, and the length of the array as well.
Then in line 236, you have to change attDeviceName[] array as well, since this parameter defines the name of your device once it is in connected state.
No way to do that in Android! unless you change your BLE firmware!
Possible solution, once you connected to your BLE device, you could send some configuration command to your device to change the device name.

getUidRxBytes() and getUidTxBytes() always return 0 in Android 4.3

I feel like I am on crazy pills right now. A specific part of my application has been working just fine for several days, and today it just stopped working and I can not figure out why. This part of my code used to output the total data since boot that each specific app has sent and received. Now, the values always show up as 0.
A couple things that may or may not be affecting this:
1.) My Nexus 4 was just updated to Android 4.3 today, but I doubt this is an issue because this worked just fine right after I updated.
2.) With the Android API 18 update, some methods from the Traffic Stats API are now deprecated, but these are methods I am not even using, so this should have no effect.
http://developer.android.com/reference/android/net/TrafficStats.html
All help is greatly appreciated.
PackageManager packageManager=this.getPackageManager();
List<ApplicationInfo> appList=packageManager.getInstalledApplications(0);
for (ApplicationInfo appInfo : appList) {
String appLabel = (String) packageManager.getApplicationLabel(appInfo);
int uid = appInfo.uid;
Log.d("data", String.valueOf(TrafficStats.getUidRxBytes(uid) + TrafficStats.getUidTxBytes(uid)));
Update[January 23, 2014]: Testing the getUidRxBytes() and getUidTxBytes() on my Nexus 4 running Android 4.4.2 shows that the values are no longer 0, but are reporting the correct statistics.
I have reported the issue to the AOSP issue tracker: here
I have also created an alternate solution to the problem which I have pasted below:
private Long getTotalBytesManual(int localUid){
File dir = new File("/proc/uid_stat/");
String[] children = dir.list();
if(!Arrays.asList(children).contains(String.valueOf(localUid))){
return 0L;
}
File uidFileDir = new File("/proc/uid_stat/"+String.valueOf(localUid));
File uidActualFileReceived = new File(uidFileDir,"tcp_rcv");
File uidActualFileSent = new File(uidFileDir,"tcp_snd");
String textReceived = "0";
String textSent = "0";
try {
BufferedReader brReceived = new BufferedReader(new FileReader(uidActualFileReceived));
BufferedReader brSent = new BufferedReader(new FileReader(uidActualFileSent));
String receivedLine;
String sentLine;
if ((receivedLine = brReceived.readLine()) != null) {
textReceived = receivedLine;
}
if ((sentLine = brSent.readLine()) != null) {
textSent = sentLine;
}
}
catch (IOException e) {
}
return Long.valueOf(textReceived).longValue() + Long.valueOf(textReceived).longValue();
}
The TrafficStats class get the information about network traffic from the /proc/uid_stat/<uid> directory. This contains information about the tcp, udp bytes and packets sent and received. If the files are not present the TrafficStats class can't get the network stats. You can check if the files are present, If not you are out of luck and should look for other way.
If the files are present you can try to read it yourself.
Also the getUidTxBytes() and getUIDRxBytes() report only the TCP traffic and miss UDP traffic. So if your app is doing lots of UDP traffic (like voip) then you'll not get any info.
There is already a bug filed for this : https://code.google.com/p/android/issues/detail?id=32410
I have done some detailed research about this, and to clarify some details, since Android 4.3 the TrafficStats API has changed in the way it extracts details from the device.
Prior to Android 4.3 the UID traffic stats were available for TCP and UDP and included API for bytes and packets & sent and received. That data was extracted from the /proc/uid_stat/[pid]/* files.
In Android 4.3, the developers has decided to switch to a better and more safe API, using the xt_qtaguid UID statistics, which is part of the netfilter kernel module in Linux.
This API (procfs) allows access based on process UID, and this is why when you try to access to TrafficStats API in Android=>4.3 you will get zero information for not-own UID.
btw, the commit that caused the issue is the following:
https://github.com/android/platform_frameworks_base/commit/92be93a94edafb5906e8bc48e6fee9dd07f5049e
*Improve TrafficStats UID APIs.
Deprecate transport layer statistics, leaving only the summarized
network layer statistics.
Improve documentation to be clear about layers where measurements
occur, and their behavior since boot. Under the hood, move to using
xt_qtaguid UID statistics.
Bug: 6818637, 7013662
Change-Id: I9f26992e5fcdebd88c671e5765bd91229e7b0016*

How do I get the UUID of a bluetooth device?

I need to know UUID on API 8 (2.2) or possibly 2.3.3.
As I understand the documentation, this should be allowed:
phoneDevice = blueAdapter.getRemoteDevice(phoneAddress);
ParcelUuid[] phoneUuids = phoneDevice.getUuids(); // Won't compile
Eclipse gives me:
"The method getUuids() is undefined for the type BluetoothDevice."
But see:
http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#getUuids()
Also, I would like to know how the UUIDs are "parceled" inside the ParcelUuid[]. In case I ever manage to get there, how do I retrieve a UUID from a parcelUuid[]? Documentation for Android bluetooth seems to be very poor, in my opinion.
What a joke!
Now I try to get it from the intent, but this too gives: *"EXTRA_UUID cannot be resolved or is not a field"*:
intent.getParcelableExtra(BluetoothDevice.EXTRA_UUID);
You have to use reflection to use the getUuids() and fetchUuidsWithSdp() on android version < 3. So, try the code:
Method method = phoneDevice.getClass().getMethod("getUuids", null);
ParcelUuid[] phoneUuids = (ParcelUuid[]) method.invoke(phoneDevice, null);
//this will support from API level 15 and above.
Broadcast Action: This intent is used to broadcast the UUID wrapped as a ParcelUuid of the remote device after it has been fetched. This intent is sent only when the UUIDs of the remote device are requested to be fetched using Service Discovery Protocol
Always contains the extra field EXTRA_DEVICE
Always contains the extra field EXTRA_UUID
Requires BLUETOOTH to receive.
Constant Value: "android.bluetooth.device.action.UUID"
//no way to degrade its hardware related. there is no supporting jar also. http://developer.android.com/sdk/compatibility-library.html
Unfortunately, I don't think there is any good way to get the UUID's supported by a BluetoothDevice with API level < 15. I guess that's why they added the new functions in API 15.
Note, from the docs for BluetoothClass
BluetoothClass is useful as a hint to roughly describe a device (for
example to show an icon in the UI), but does not reliably describe
which Bluetooth profiles or services are actually supported by a
device. Accurate service discovery is done through SDP requests, which
are automatically performed when creating an RFCOMM socket with
createRfcommSocketToServiceRecord(UUID) and
listenUsingRfcommWithServiceRecord(String, UUID).
So, perhaps the device class could be used as a hint as to what services will be available until you perform one of the listed functions. Certainly it doesn't hurt to check the class since this won't require any additional bluetooth operations.
Note that the service class is also available (it is part of the device class) but this is just a general class, not a listing of specific services (like from SDP).
try BluetoothAdapter class
any question, read: http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html
In case you can not get UUID from getUuids() method. Please try the other way.
After scanned successfully, you should receive byte[] (scanRecord), so from this result, if you can recognize UUID format you can split step by step to get correct UUID as these codes.
P/s : Important thing, you should know UUID format to get from index correctly.
// Put item into hash map
// UUID from index 10 to 24 : 12233445566778899aabbccddeeff0
StringBuilder mSbUUID = new StringBuilder();
for (int i = 0; i < scanRecord.length; i++) {
// UUID
if (i >= 10 & i <= 24) {
if (Integer.toHexString(
scanRecord[i]).contains("ffffff")) {
mSbUUID.append(Integer.toHexString(scanRecord[i]).replace("ffffff", "") + "-");
} else {
mSbUUID.append(Integer.toHexString(scanRecord[i]) + "-");
}
}
}

Categories

Resources