Run FFmpeg executable from sdcard - java

In my android application, I have to concat videos of different formats and i use FFmpeg for this.I made use of the java wrapper provided by guardianproject at the below link:
https://github.com/guardianproject/android-ffmpeg-java
But this method uses the FFmpeg executable. Some of the guys suggested to avoid this approach, because we need to issue permission to run the executable s since android will not do that.
Also this can only be possible when the app's data is in phone memory.So the problem is, the app cannot be moved to sdcard. When we do so, the executable cannot be run.
I feel this method is good when compared to writing JNI. So is it possible to issue permission to a executable that can run on a sdcard.
Any help is appreciated.

You can issue permissions pragmatically to any files that resides on sd-card. Create a file object and try this
file.setExecutable(boolean); – true, allows execute, false disallows it.
I hope this works.

Related

How to write to local PC file from Android emulator app

I've been searching for hours and came across a lot of non-sense about read-only this and that and folders and directories and viewing the phone fs, etc. etc.
All I want to do is write to a file that is on my PC for an Android project. I've tried to use local paths (Windows) and have been met with read-only fs system problems, even after completely converting the desired folder to read AND write, Android refuses to get it. I set uses-permissions in my manifest with WRITE_EXTERNAL_STORAGE and WRITE_INTERNAL_STORAGE, but no luck.
I've tried to write to the phone, via emulator and actual physical phone, but every search I make turns up nothing (searching for the name of the file).
How can I write to a log file, any file that is where my development source code is? I need to digest JSON data from a web service call and I need it to be written to a local file so that I can work with it. The calls are through Android, currently an emulator, and an install on a physical device, yet no log is written because either a read-only problem which is non-sense, or I just can't find the damn file.
Any help would be greatly appreciated.
I guess ultimately the question I asked was just too messy. I wanted to know where I could find "local" logs on my Android device, which I can open and read myself in some text editor. I also wanted to know where "local" logs/files are written to my hard disk when testing the app via emulator.
At this point, I haven't found anything relating to a log file or any arbitrary file being able to be written from an Android app to a local dev PC without being pulled from something like adb.
I have found the solution to where I can write arbitrary files to an emulator or phone's filesystem (Source: https://www.journaldev.com/9383/android-internal-storage-example-tutorial):
FileOutputStream fos = Main.getAppContext().openFileOutput( "myfile.txt", Context.MODE_PRIVATE );
fos.write( "Hello, world".getBytes() );
fos.close();
Some things to note (Android SDK 26+ at least, others are untested):
FileOutputStream works very well.
"Main" refers to whichever entry point class you're using for your app. It most likely (or must?) extends AppCompatActivity.
Context.MODE_PRIVATE seems to be required.
AndroidManifest.xml permissions READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE, READ_INTERNAL_STORAGE, WRITE_INTERNAL_STORAGE do NOT seem to be required.
Important: Files will be saved to /data/data/YOUR.APP.PACKAGE/files/.
This was also helpful: https://developer.android.com/training/data-storage

Copy files from Android's Gdx.files.local() folder to developing machine

LibGDX: I have game-data files created at runtime for debugging purposes (a replay system). The files are stored in Gdx.files.local() whether on desktop or android. Now I want to copy the ones that were created on android so I can debug them on desktop.
Running Gdx.files.getLocalStoragePath() on android returns /data/user/0/com.[my domain].[my app]/files/. Using Windows Explorer I do not see my app's folder in /data/user/0, or anything else for that matter. So private storage indeed it is, but how nonetheless can I get hold of these files, without root if possible?
The solution may be manual copy or in code, whatever works. Just to note, the file names are unknown without seeing the files first. They were named using current date-time. The extension is known, though.
EDIT
I discovered Android Studio's Device File Explorer. I connected my device, tried to see inside my app folder and app data folder, both showing 'Operation not permitted'.
So to put the question in simpler words, is rooting the phone really the only way for developers to see the files created by their apps?
Or is there a magical gate somewhere known only to select few zen masters who guard the secret through the generations? Because I sure ain't finding it.
I'm not sure that there is a way to write changes in the system file without having root access but you can read them. According to this Blog, You can access those files and put it in your desktop. You can download RAR app from googleplay.

How to load and save files in Android?

I need to load "configuration" type files for my program in Android, they are both .bin files containing dictionary data for the NLP library. I'm a bit new to Android still, and I'm having trouble finding a folder to place the files in so I can access them when the activity starts.
I also need to create/save/load a filetype specific to my program, and I don't know where to put it either. All I've been able to find on here is people using the getAssetManager() function to fetch input streams, but I explicitly need File objects for me to be able to load them into my pre-existing desktop software code I'd like to reuse (plus the libraries require them anyway)
I've also seen people using a "res/raw" folder, however the ADT did not generate this "raw" file when I made the project - so I'm not sure what to do there either.
Here is how I usually start the software in the desktop version, but I need to fetch these files in an Android environment:
brain.start(new File("memboric.core"), new File("en_pos_maxent.bin"), new File("en_sent.bin"));
core = brain.getInterpreter().getCore();
The memboric.core file can be generated, but I need to know WHERE and HOW to do so.
Thank you very much for your time, feel free to direct me to other resources if you feel this question is inadequate.
TLDR; how do I load "static" files for the software to function (needs to be included with software), and how to create/load/save "personal" files into an appropriate area of the device?
Use Context.getFilesDir(). Your application can read and write files in that folder and they'll automatically get deleted if your application gets uninstalled.
From that point forward, you can create, delete and read from files like any other Java application.
the "raw"-folder you can create it on your own. So check this out, which shows how to handle files in Android: http://developer.android.com/training/basics/data-storage/files.html

Changing directory permissions

I need to get write permissions to the lib directory of my application (i.e. /data/data/com.my.app/lib/) and store a file there, and I need to do it from my application. Is it possible? and if so, how?
EDIT
By my application I mean using Java. /data/data/com.my.app/lib/ is the path to the lib directory of the same application.
EDIT
Unfortunately, as LeffelMania said, I couldn't find any convenient way to do it. Fortunately, we solved this problem in a better way - we convinced the developers of the library to make it more dynamic :). Thanks again LeffelMania.
It is not possible to directly write into another app's file space. Your app has write access to its own space and external storage (SD card) with permission.
However, I can imagine a couple ways to do this, depending on what you're trying to do, specifically.
1) Write the file to the SD card from one app. Have the other check if it's there and read from it when it opens. Make sure to write it to your own proprietary folder - don't clog the user's storage space. If applicable to your situation, delete the file and your folders on the SD card from the other app once you've read the file.
2) Register a custom BroadcastReceiver in the recipient app, and stick the data you need to transfer inside of an Intent that you will send from the other app. You should use your own action String so that no other application in the system attempts to use your Broadcast.

Set write permissions on ProgramData subfolder using JNA

I have a program, written in Java, which originally used its directory in Program Files to write files accessible to all users of this program. This required our users to run as administrator all the time. In an effort to alleviate that, we decided to move files which needed to be written during regular usage to the ProgramData folder using the %ALLUSERSPROFILE% environment variable. Using a subfolder in this directory for our application works great if it is designated as writable during the installation process, which works fine using NSIS.
The problem comes with upgrading existing users. The Java File API provides setWritable but this does not appear to work after testing on development machines. It looks as though the new file API with Java 7 would solve this problem, but with no release date on the horizon I would rather not wait.
It seems the simplest solution would be to use JNA to call the appropriate Windows API call to set this directory writable. Since upgrading the software necessitates admin rights, similar to installing, it should let this change go through fine. However, I'm unsure where to start, having never used JNA before or the Windows API. Suggestions as to which Windows library to load and what functions to call would be appreciated, especially if someone has encountered a similar problem before.
Well, I'm glad you gave some background...You could use JNA, but the easier way would be to execute a call to the command-line utility cacls. It's included by default in Windows XP installations, I believe, so it should do the trick for you. Try Runtime.getRuntime().exec("C:\\Windows\\System32\\cacls.exe"+options)
Check out the documentation here -> http://technet.microsoft.com/en-us/library/bb490872.aspx
I use the follow line:
Runtime.getRuntime().exec( "C:\\Windows\\System32\\icacls.exe \"%ProgramData%\my application" /grant *S-1-5-32-545:(OI)(CI)(W,M)" );
S-1-5-32-545 is the SID for BUILTIN\Users because the name work only on English systems. https://support.microsoft.com/de-de/kb/163846
This give the BUILTIN\Users write access to all files in the given directory independent which user has create it.

Categories

Resources