Detecting/Verifying SD Card Drive [duplicate] - java

This question already has answers here:
Detect USB Drive in Java
(5 answers)
Closed 2 years ago.
Is there a way to detect all SD Card drives connected to a Desktop computer? In Windows, SD Cards are visually distinct from other devices like built-in hard drives or similar. Is there a way to tell if a drive is an SD Card drive or not?
A Java way of listing all available filesystem roots for example is using the listRoots() method but it cannot tell the filesystem types such as external, internal, OS drive or whatever.
Is this even possible in pure Java?
Note:
I'm not asking to detect the Android phone SD Card since these are the results when searching for my question.

This answer solved it.
Example code:
USBDeviceDetectorManager manager = new USBDeviceDetectorManager();
List<USBStorageDevice> usbStorageDevices = manager.getRemovableDevices();
for(USBStorageDevice usbStorageDevice : usbStorageDevices)
{
System.out.println(usbStorageDevice.getSystemDisplayName());
System.out.println(usbStorageDevice.getDeviceName());
System.out.println(usbStorageDevice.getRootDirectory());
}
I have my SD card, NAS, C: and D: drives connected. The following is printed:
SANDISK (E:)
SANDISK
E:\
As expected, only one result is returned because the SD card is treated as USB due to the USB reader being plugged into my laptop.

Related

Reading and writing to EMV card

This is something new and I've never done any coding related to online transaction or debit/credit cards. I was told to study about EMV(EuroPay Master Visa) card to implement it in Android App.
So far, I have collected info about
APDU
file structure
"APDU Command" is sent to get useful info from card.
APDU fields (CLA, INS, P1, P2, Lc, Data, Le)
"APDU response" is sent back from card to card reader.
All these processes happen between the card and the card reader.
In my case, the card reader is attached to an android device. I may need to display card details to user in android app (Ex: Displaying last 4 digit of card number).
My questions are
what are the possible values in APDU command fields if i want to authenticate card.?
How to communicate between card reader and device using Java.
PS: I don't need any codes. I just need a simple explanation, I will continue R&D once i understand the concept.
What you are asking for is an EMV course, that's a lot for a SO question.
As outlined by #kushal, you'll have to go through the EMV Specifications, they contain a lot of command samples, and will describe the sequence of commands required to complete a transaction.
But by doing so, what you're trying to achieve is to write an EMV Kernel, which is costly and time consuming, as outlined in this SO question. Count a couple of years of development for this, not taking into account the bank integration part... If what you want to achieve is just to process transactions, what you want to do is to buy an EMV kernel (ex : from level2kernel, verifone, Ingenico, etc.).
You can take a look to an example of a an Interac Flash transaction (contactless EMV) here, that will give you an overview of the complexity of the protocol.
EMV Card SpecificationFirstly you have understand the EMV 4.2
Then You have to communicate with the reader to android device by the help of UsbManager Class. then send the specific APDU`s to the Card then the card give the Following information.

Is it possible to Turn Off USB Storage on Android Devices programatically?

I have tried to search over and over and got confused whether we can have control over USB storage without rooting the phone,if yes than how? I have tried the following method to enable and disable the permission but all in vain:
StorageManager storage = (StorageManager)getApplicationContext().getSystemService(STORAGE_SERVICE);
Method method = storage.getClass().getDeclaredMethod("enableUsbMassStorage");
method.setAccessible(true);
Object r = method.invoke(storage);
//And to disble mass storage:
StorageManager storage = (StorageManager) getApplicationContext().getSystemService(STORAGE_SERVICE);
Method method = storage.getClass().getDeclaredMethod("disableUsbMassStorage");
method.setAccessible(true);
Object r = method.invoke(storage);
If anyone has any idea about this please do share your knowledge.
Thanks in advance.
The short answer to your question is NO. You cannot play around with the USB mass storage permission programmatically. You also wont find any Android apps that can do this reliably for any/all phones.
By default, the Android framework does not allow third-party applications to programmatically bypass the USB storage permissions. That choice is always left to the user, and that is the correct approach. Just think about it: if it were permitted, any third-party app could misuse that permission and transfer data over the USB connection.
The approach you have tried to use assumes that we know the names of the relevant methods and call them through reflection. This will work for certain OEMs' that have modified the base framework and exposed the relevant API calls. But it assumes that you know the names of those methods, and it will only work on a tiny subset of the vast number of Android phone models out there. It won't work on most phones, and it certainly wont work on any of the Nexus devices that have the original Android OS source code.
That is all.
If currently your Sd card is SHARED it means that it has connected to PC in MSC mode, you can check this case as following:
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_SHARED.equals(state)) {
// Sd card has connected to PC in MSC mode
}
Now You can force to turn off usb mass storage connection by calling:
MountService.setUsbMassStorageEnabled(false);
//or
StorageManager.disableUsbMassStorage();
//but unfortunately, both these API are not public accessible?!

How to get mobile number phone on android 4.1.2 ? [duplicate]

This question already has answers here:
Programmatically obtain the phone number of the Android phone
(22 answers)
Closed 9 years ago.
I want to get mobile number of own mobile, for add this part to my application .
I'm searching about this question ,
code is correct on emulator but in device show empty.
public String getMyPhoneNumber()
{
return ((TelephonyManager) getSystemService(TELEPHONY_SERVICE))
.getLine1Number();
}
and :
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
But is it returning empty value. So How can I fetch the phone number detail ?
The method you are using is the only one part of the SDK to do this, and only works on devices where the number is stored on the SIM card, which only some carriers do. For all other carriers, you will have to ask the user to enter the phone number manually, as the number is simply not stored anywhere on the device from where you can retrieve it.
Answer from: Programmatically obtain the phone number of the Android phone
"There is no guaranteed solution to this problem because the phone number is not physically stored on all SIM-cards, or broadcasted from the network to the phone. This is especially true in some countries which requires physical address verification, with number assignment only happening afterwards. Phone number assignment happens on the network - and can be changed without changing the SIM card or device (e.g. this is how porting is supported).
I know it is pain, but most likely the best solution is just to ask the user to enter his/her phone number once and store it."
Your code should be fine, but you need the SIM card to be inserted in the phone. Also, as autocrat noted, if the number is not stored on sim card, you will get an empty string.
EDIT: Also, please check the link provided by Pontus Backlund, there's some good info there.
Go to setting -> about device -> status -> my phone number if my phone number is unknown u won't get mobile number.. because some of the mobile network won't give mobile number..
if my mobile number has number u can get mobile through following code
TelephonyManager tManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
phoneNumber = tManager.getLine1Number();

How to get IMEI for J2ME supported all devices? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
how to dynamically get mobile IMEI number in J2me?
is there any way to get IMEI for J2ME supported all devices??i did some googling and find out the below solution but it is for device specific.
Nokia.
System.getProperty("com.nokia.IMEI");
SonyEricsson
System.getProperty("com.sonyericsson.imei");
Motorola
System.getProperty("com.motorola.IMEI");
is there any generic way to fetch IMEI for all devices??
There is no generic method to fetch IMEI for all devices, you have to do it by coding only. You can try it in alternate way like use System class as follows,
System.getProperty(“microedition.platform”);
This will going to return you the name of the host platform or device. In Nokia devices the name consists of “Nokia”, the device model, and software version separated by “/”. There is no space between “Nokia” and the model number nor on either side of “/”. Formally, the syntax of the platform string is: Nokia MODEL_NUMBER “/” SW_VERSION. For example, Nokia6310i/4.42 or Nokia3510i/p1.25.
From the result you can fetch the manufacture and use Switch case to get IMEI by coding,

How to determine the number of SIM cards on a device?

Sometimes we encounter some devices which have two or more SIM cards. So my question is:
How can I determine the number of SIM cards on the device?
Actually, I am developing a field test app and for example, if I have 2 SIM cards on the device, the user can choose between them to launch measurements.
There is currently no Android API for handling multiple SIM cards; any device support is entirely down to the handset manufacturer having modified the Android source. You could see if the particular manufacturer offers any kind of SDK or published API to help you, but it will be on a case by case basis.
All phones that support multiple sim card switching do so outside the android SDK so you'd have to contact their manufacturers for information about how they expose this functionality.
The question is very outdated and probably the answer was already found. But this may help someone else.
Beginning from Android API 22 you can do so via the SubscriptionManager like below:
val subManager = getSystemService(TELEPHONY_SUBSCRIPTION_SERVICE) as SubscriptionManager
val simCount = subManager.activeSubscriptionInfoCountMax //Total supported sim cards by device
val simAvailable = subManager.activeSubscriptionInfoCount // Currently active sim cards amount

Categories