Programmatically write to an android device - java

I would like to write a program in java that copies mp3 files from my PC, renames them so they sort correctly, and transfers them to the sdCard on my Android phone via USB. I assumed this would be a trivial task since I have already successfully written a similar program for transferring files to an external HDD, however I reached an immediate stumbling block. It seems that java (and indeed other desktop applications) cannot locate the device's file system even when given the exact path that windows explorer reports (This PC\SAMSUNG-SM-G900V\Card).
I've tried researching and the problem seems to have to do with the device being considered a Portable Device rather than a drive (maybe) but I have not found a concrete solution. An answer to the following question seems to suggest it is impossible but I find that hard to believe.
Can Android's internal memory be mapped to a drive letter on PC?
Does anyone know of a way to access Portable Device storage through java? If if it indeed impossible, can someone perhaps help me understand why it is possible through Windows Explorer but not through other programs.

Related

How do I run an apk on J2ME?

Whats up! I just want to ask, but how do I run an .apk file j2me. I know that this question HAS been asked, but I can't seem to find an answer. Also, i'm not asking to run j2me apps on android; there are already tons of emulators. Im asking for apks running on j2me. I also know that they are developed in different VMs. So, is there any way to do that? Also, another side note, how do i resize the screen of an apk file? Thanks!
-Apersonwithalaptop22
(Edited to be easier to be understood)
You don't. A J2ME environment wouldn't have the Android framework. You'd need to write a complete android framework in the j2me language. It's not as simple as just converting dalvik bytecode to jvm bytecode- it's actually providing every single android class in the SDK. It could be done, but it would take one person a few years to do, and some things would never work quite right. Possibly you can find a project that's tried to start that effort, although I would doubt it- android moves relatively rapidly for them to keep up, and j2me is basically dead.
As for resizing the screen of an APK file- you don't. APK files don't have a screen size. Instead the idea is to write a UI that scales.

Certain Phones delete SQLite DB

I've got an app created with Android Studio.
I'm using an SQLite database which gets downloaded and saved in phone's storage.
The problem is that in certain types of phones (Lenovo / Xiaomi to be exact) the sqlite file gets deleted after some time and the users have to re-download it.
The problem is appearing only on these 2 types of phones and also not all of them.
I can't replicate that on any of the phones I tried nor emulated ones within Android Studio.
There is no code that would delete the SQLite file and also I couldn't find anything in here or google about Lenovo/Xiaomi having similar problems like mine.
Any Ideas, would be appreciated.
I don't know about Lenovo, but Xiaomi phones have a "Clean up" feature that regularly (at least once a week, in my experience) asks the user to, well, let it clean up files. I don't know what it uses to decide if a file is obsolete or not, but it is a very aggressive cleaner (it wants to clean up cache files for apps that have just been used and are in constant use, for example). This is likely what is removing your downloaded files. You can check the location you're downloading them to, and see if changing that helps; or you could see if you can find any documentation on the file cleaner so you can find out how to stop it from flagging your DB as "rubbish".

How to access adc and dac directly on android phones?

I am at the beginning stages of a project in which I will be trying to make a hearing aid application for Android. I have wrote a few patches in Pure Data,C sound, and the basic Android sound library which basical take the input from the microphone and play it through headphones. No filtering or amplification.
While Csound gave the best performance, the latency made the tools unusable. I know Android L is suppose to help, but my goal is to create a low cost device hearing assist device. So older phones probably won't get it.
The next idea is to see if I can access the adc and dac values directly, then use C to make my own versions of AudioTrack and Audio record by using the NDK. Basically pointing to the places in memory where these values are coming in.
Is this possible? Also what should I be researching? I can't find anything online about accesses the DAC and ADC directly.
Thank you for your time.
No. "Android" does not provide for direct access by apps to hardware at all.
The NDK does not change that, as you still lack permission to the audio hardware device nodes.
If you have a particular device on which you can install a customized build of Android, then you might be able to do something by adding new APIs or somehow giving your app or a special unix group access to the hardware nodes. But the details of how you might utilize that access would depend on the device chosen.

How can you access USB from cross-platform Java?

I need to copy some files from a PC into a pen drive. I visited JUSB package description, but it is only for windows. So, is there any easy and platform independent way to copy files from computer to USB drive using Java?
You don't need to worry about the fact that it's a USB drive; when the user inserts the device it is recognized by the OS and shows up as a mounted drive in your filesystem. Then you can just use java.io.File and friends to access it. Additional tip: use org.apache.commons.io.FileUtils as a handy toolkit to make many common file-related tasks easier.
If you need to detect the new USB device automatically in Java, that's a bit tricky. See this question.
You can take a look at libUsb Java Bindings a javabinding for libUsb. Btw. the jUSB API seems to support Linux too (package: usb.linux), maybe this article can help you: Access USB devices from Java applications

java - copy files from mobile device

I'd been trying to make this little desktop java application to backup some predefined files from an android tablet/smartphone to my computer.
Up to now I'd been using mainly the File.getRoots() function to reach every single drive with no trouble. I successfully tested this on two android phones, but the problem came when I tried it on a Galaxy Note. Unlike the first two. this device is not treated as "removable media" but as a "mobile device". Therefore, I can't reach it using my current method, it's just not "listed".
I'd also looked if there's a way to reach those mobile devices through cmd, hoping that helps, but haven't found anything usefull.
My goal is to backup just by plug > run-application > unplug.
So, that's it, i'm stuck! Any clue?
Thanks in advance :D

Categories

Resources