Extract a version number from bar-descriptor.xml file programatically - blackberry-10

Is there a way to extract a version number and other information from bar-descriptor.xml file similar to how it's done in Android world via getPackageInfo() in PackageManager?

For some reason missed classes which allow to do this exactly:
PackageInfo
ApplicaitonInfo

Related

Native file path

I have started a development of a music player. I made some additional kotlin logic to retrieve all audio files meta data on device from the Android as a list of meta data. I'm trying to understand how a native path should look like for just_audio to understand. My current implementation uses a deprecated key - MediaStore.Audio.Media.DATA for contentResolver which returns a path like this /storage/emulated/0/Download/scifri20181123-episode.mp3. Can this path be used by the plugin or I need to find another way to retrieve the path in different format?
The same question is valid for the album art.
Yes, if it's a valid file path, then just_audio will be able to open it. You could pass this into setFilePath:
var filePath = '/storage/emulated/....../foo.mp3';
await player.setFilePath(filePath);
This is a convenience method for:
setAudioSource(AudioSource.uri(Uri.file(filePath)));
where Uri.file(filePath) will create a Uri instance containing something like file:///storage/emulated/..... under the hood.
Note that if your app tries to access any file outside of its own app data/cache directories, it also requires permission to do so, and there are other Flutter packages available to help you with this.
Note also that there is also an existing flutter package using the content resolver API called flutter_audio_query, so if it contains what you need, you might not need to write your own Kotlin code.

How to open/find the file created by path_provider?

I'm a beginner at flutter and dart and had some issues with file handling using flutter.
I'm trying to store data locally in text files for my flutter application, and came across the standard tutorial on flutter's website which used path_provider and dart:io. It had instructions on getting the path and reading and writing to a file, however this didn't seem to work for files I added to the project. The only way to store to files was to first write using the inbuilt functions, then reading this newly created file. I can't add my own file and read it using flutter.
I also can't open the file created by flutter as I don't know where its stored. The path given by getApplicationDocumentsDirectory() returns the path /data/user/0/com.example.daily_challenges/app_flutter, and I don't know where to find this in my project.
In summary: How do I read a pre-existing file and how do I view the file created automatically by flutter.
Thanks :)
You can access the files from a physical device or simulator through Device File Explorer in Android Studio. Follow this guide
You won't be able to access getApplicationDocumentsDirectory().
If you are using android device, you can try to store it in getExternalStorageDirectory(). There's no equivalent in IOS though.
If you are running in a physical device. Open Device File Explorer in Android Studio and you can find the file under
data/data/your app package/app_flutter/fileName.txt
For example,
data/data/com.example.file_example/app_flutter/example.txt
And if you want to read the pre-existing file, you not need to anything specific, if you give the same file name, if not exist, it will create one, otherwise it will return the old one.
final File file = File(filePath);
file.writeAsStringSync('${text}', mode: FileMode.append);
For write, you consider using FileMode if you want to append text to the existing file. Or else by default overwrite will happen.
For read, you can consider this
final File file = File(filePath);
String text = await file.readAsString();
Just use Device File Explorer from Android Studio.
But the weird thing, path_provider gives you path like /data/user/0/your_app_id/..., but in fact all files are located in /data/data/your_app_id/..., as mentioned in previous answer.

Is it possible to download and execute an uncompiled dart file (Flutter)

I am trying to make an extension based app, where you can download extensions to the app to add features/widgets. Could I somehow run an uncompiled dart file downloaded from a server that stores the .dart files?
download(file.dart)
compile(file.dart)
storeInPersistentDirectory()
if (dartFile.exists) {
ClassFromDownloadedFile.sayHello()
}
The aim is to decrease the app size by storing all of the data related to an extension in the dart file, (classes, json and images in the form of a string...). Users might want to download features, while some don’t need them, in which case they shouldn’t need to download a large app with many features that they will never use, so the initial app size remains small.
Thank you for anyone who knows anything relating to this in advance!
No, it is not possible. You can download a 'resource' such as image/video/mp3 etc. You can even download the dart file but can't compile and execute.
there is a concept in dart and other modern languages called reflection(mirroring).
Reflection allows us to examine and modify the structure and behavior
of a program at runtime.
search about it and check the below links for more information.
dart document
Understanding Reflection and Annotations in Dart
I recommend searching for RMI too.

How to create APK Expansion Files for assets within flutter

I have created a flutter app with video assets which are about 450mb in size. I have published the app successfully in the Apple appstore. But Google Play does not accept my APK as it is over the limit of 200mb. I tried to go with the approach of creating APK expansion files as the recommended workflow. I have read all available Android documention about expansion files but I still can not figure out how to implement them with flutter.
How do you implement and access assets within APK expansion files in a flutter app?
You're going to have a little bit of fun with this. Basically, until someone implements a plugin to access APK expansion files, you're going to have to write the java code to connect up to Flutter.
It's not prohibitively difficult, it just means that you're going to have to learn about Platform Channels and write a bit of native android code. The documentation probably does a better job of explaining platform channels than I do, but basically the easiest way is to use a MethodChannel to pass data from dart to native and vice-versa.
What you'd do to start is set up a method channel to initiate this process and call it with something like getObbFolder.
On the android side the first thing you need to do is make sure your app actually has the files downloaded. According to the android documentation, you can't guarantee that they will have been so you need to write the logic to download them. I'd recommend using the Download Library they provide as there's all sorts of things to worry about like the device running out of storage, network connectivity, showing progress, etc. I think the documentation for that is moderately straight forward (and if you have issues I'd recommend asking a new question specific to it.
Once you've done that, you need to get the path to the file, and request permission to read it if needed. Some android versions and some devices in other versions (it sounds like it's a bit of a crapshoot to be honest), you need permissions to read the file, while in others you don't. So it's best to just try and ask for permission if trying fails.
To get the directory it's saved in use context.getObbDir()
Then this one way to do it from the android docs:
File obb = new File(obb_filename);
boolean open_failed = false;
try {
BufferedReader br = new BufferedReader(new FileReader(obb));
open_failed = false;
ReadObbFile(br);
} catch (IOException e) {
open_failed = true;
}
if (open_failed) {
// request READ_EXTERNAL_STORAGE permission before reading OBB file
ReadObbFileWithPermission();
}
And for the versions that don't do runtime permission checking add this to your application manifest:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Android doesn't recommend always asking for the permission since sometimes the Obb folder is exempted from needing the READ_EXTERNAL_STORAGE permission.
Now you have two options. One is that you could pass that path back to flutter, and then use flutter's file reading to do something with the data, if the file is something you can directly read. If it's not, you could unpack it either using flutter or using java/kotlin, and then pass back the path to the unpacked files.
If you do choose to unpack the file from android you should do it to one of the directories flutter knows about (with the path_provider plugin for example), or write to wherever you want (and have permission to) and then simply pass the path back to flutter.
Hope that helps!

Where are the headers for libbz2.dylib for the iPhone?

The headers for libbz2.dylib on the iPhone are missing, or contained in a less than obvious location. I've looked for bzlib.h, bz2lib.h, bz2.h, etc., grepped for patterns, and found nothing - are they included with the SDK, or do I need to just pull the header from the main libbz2 distro and use that instead?
Since the library is clearly available on the device, the header really should be in the SDK, but it appears that it isn't. I'd use the one that's packaged for the Simulator, since this is most likely to be the same as the one on the device:
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.1.sdk/usr/include/bzlib.h
Then open a Radar case to ask that the distribution be fixed.
From the site below get the bzlib-0.5.0.0.tar.gz file and copy the files (.h and .c) inside the cbits directory to your Xcode project.
http://hackage.haskell.org/package/bzlib
So far it seems to work, I've managed to read the contents of a .bz2 file with the functions BZ2_bzReadOpen and then BZ2_bzRead.