I have an AS3/AIR application for deploying on Google Play. The app has an expansion file attached to it. The expansion file is named "main.1000000.air.com.mycompany.myapp12.obb" and it is downloaded along with the app properly.
The problem is I cannot access the expansion file any way I tried, like:
File.applicationStorageDirectory.resolvePath('Android/obb/main.1000000.air.com.mycompany.myapp12.obb');
File.applicationStorageDirectory.resolvePath('/Android/obb/main.1000000.air.com.mycompany.myapp12.obb');
File.applicationStorageDirectory.resolvePath('main.1000000.air.com.mycompany.myapp12.obb');
File.applicationStorageDirectory.resolvePath('/main.1000000.air.com.mycompany.myapp12.obb');
and similar variations. I cannot access the file even when the path while developing on Windows seems to be right. When deployed, I just got the "not found" error in my catch block with the supplied File url property: "app-storage:/Android/obb/main.1000000.air.com.mycompany.myapp12.obb" . I have been looking for the solution and trying various approaches for several days, but I am stuck. Developed on ASUS EEE PAD.
Try this:
var path : String = "Android/obb/air.com.mycompany.myappli";
var filename : String = "main.1000000.air.com.mycompany.myappli.obb";
var file : File = File.documentsDirectory.resolvePath(path + "/" + filename);
if (file.exists)
{ ... }
Hope this help
Related
For the last 2 weeks I've been successfully converting a WPF application to a Xamarin.forms android app. Everything works as intended except for 1 thing. I've been searching the web for a few days for a solution but I can't find a working solution.
This is my current setup:
Xamarin.Froms android app
Target android version: Android 10.0
Minimum android version: Android 7.0
Xamarin.Essentials version: 1.6.0
READ_EXTERNAL_STORAGE permission
WRITE_EXTERNAL_STORAGE permission
My app should be able to open a selected file, using the Xamarin.Essientials FilePicker, Do some stuff and save the File again to the same path. The file selection is handled in the following code:
var pickresult = await FilePicker.PickAsync();
if (pickresult != null)
{
try
{
var result = await pickresult.OpenReadAsync();
var reader = new StreamReader(result);
var jsonstring = reader.ReadToEnd();
ConfigData = JsonConvert.DeserializeObject<ProjectData>(jsonstring);
PLC_Data.ProjectLoaded = true;
L_LoadedProject.Text = pickresult.FileName;
ProjectData.Filepath = pickresult.FullPath;
reader.Close();
result.Close();
//Load login page
B_Next.IsEnabled = true;
}
This is where the problem occurs. Let me clearify what happens step by step:
The FilePicker opens a File picking window.
I navigate to my preferred file in the "download" folder, could be any folder.
The file is read and converted to an object
The file path is saved
when i check the filepath i get the following string:
"/storage/emulated/0/Android/data/com.FAIS.motorconfigapp/cache/2203693cc04e0be7f4f024d5f9499e13/303bc84665374139b6303c03255e9018/config1.json"
So the FilePicker copies the "External" file to the App cache folder and returns the filepath from the Apps cache folder. When i check this folder there is indeed a copy of my selected file inside it. Reading from and writing to this file works as it should.
Now the actual question:
Why does the FilePicker copy my selected file to his cache folder and how can i prevent it?
The user should be able to select a file from anywere on the device and find the updated file in the same location.
I've checked all my settings and in my opinion everyting should be correct so i don't get why a copy is created. Does anyone have an idea?
If you need more settings, pictures, versions please ask.
Thanks in advance
I wrote a test Android app in Xamarin, where sample data was stored in a file. Somehow I copied test data file to emulator, successfully run the app and forgot about the project for couple of months.
Now I am resuscitating the project and - I can't find the file in Android Device Manager although it is still accessible in the emulator. It drives me nuts, I need to edit it!
Perhaps someone can point me to the right way to locate the file. Thanks!
Following is the code fragment that reads the file. I added debug output in the comments after each relevant line
var fileName = "NursePurse.jobjson1.txt";
var assembly = typeof(pageJobs).GetTypeInfo().Assembly;
//assembly.base.CodeBase = "file:///storage/emulated/0/Android/data/NursePurse.Droid/files/.__override__/NursePurse.dll"
String fname = assembly.FullName;
//fname = NursePurse, Version=1.0.6504.22050, Culture=neutral, PublicKeyToken=null
Stream stream = assembly.GetManifestResourceStream(fileName);
List<String> t = assembly.GetManifestResourceNames().ToList();
// there are two entries
// "NursePurse.AppResources.resources","NursePurse.jobjson1.txt"
// here is my file! But I don't see neither of these files in the android device manager.
Question - where is it?
Following is the screenshot of Android Dev.Manager View and Device definition with SIM card
Using the Android sample in the WebViewer folder I have an application in Android Studio which when run on my device works and displays the xod file given as expected. However I've tried to change the lines:
String documentPath = getFilesDir().getPath() + "/GettingStarted.xod";
InputStream in = getAssets().open("xod/GettingStarted.xod");
to
String documentPath = getFilesDir().getPath() + "/sample.pdf";
InputStream in = getAssets().open("xod/sample.pdf");
And have also changed the endsWith(".xod") to endsWith(".pdf") but I only get a grey screen. For this to work does the file have to be a .xod? As it works for xod files but not pdf files.
Thanks for your time.
Yes, for mobile viewing you need to convert your files to the web-optimized XOD format.
The PDF backend for WebViewer is not available for mobile browsers. This is due to limitations of the hardware and the mobile browsers.
For desktop browsers, to switch from XOD backend to PDF backend, you need to follow the steps. See here for more details, especially if you run into any errors.
var myWebViewer = new PDFTron.WebViewer({
path: "lib",
type: "html5",
documentType: "pdf",
initialDoc: "GettingStarted.pdf"
}, viewerElement);
Notice the documentType parameter is set to pdf.
I am using as3 air and testing on an android.
I need to able to load, thru a browse feature, the sd card
OR
I need to point directly to that file folder thru a path.
I have successfully downloaded a zip file from a server. I can unzip it while testing on
my desktop because I can browse to the correct path on desktop but not on phone. But I don't need the browse feature anyway, right now. I just need to be able to point to the applicationStorgeDirectory and the file in there. :)
I need the file var :)
var reader:ZipFileReader = new ZipFileReader();
reader.open(file); /// Help :)
UPDATE Sept 4th 2012 5pm
I tried this code:
var file:File = File.applicationStorageDirectory.resolvePath("myFile.zip");
trace(file.url); //path to the file
//assuming that function takes a string path
reader.open(file.url);
and I got this error:
Scene 1, Layer 'Layer 1', Frame 1, Line 46
1067: Implicit coercion of a value of type String
to an unrelated type flash.filesystem:File.
This should give you a url to an existing file
File url
You could try something like this:
var file:File = File.applicationStorageDirectory.resolvePath("myFile.zip");
trace(file.url); //path to the file
//assuming that function takes a string path
reader.open(file.url);
Try the following. I've tested.
var file:File = File.applicationStorageDirectory.resolvePath("myFile.zip");
trace(file.url);
reader.open(file);
How to display .mht(MHTML) file on android webview. I tried to open the .mht file on default android browser but that didn't open but i am able to open same on opera mobile browser. So i tried with MHTUnpack java library. I didn't succeed in that.
Here's a link!
Please if anybody has used this MHTUnpack let me how can i use that in android. And also let me know if there is any other library.
Thanks
Found this unknown google project which appears to be working.
This utility decodes the mhtml file and save it on given path(internal or external). After saving it returns the html file path which could be loaded into webview.
Try it.
After overcoming frustration about WebView.saveWebArchive() format change in Android 4.4, I tried the "unknown google project" Chitranshu Asthana mentioned in his answer, but code provided there is slow (~10s for 1MB *.mht file with a dozen of pictures) and doesn't handle attached file names correctly.
MHT Unpack library combined with Java Mail for Android (not the one provided by Oracle) worked perfectly for me.
EDIT: Fixed the link to MHT Unpack library. Also, here's usage example:
// contentPath - path to input .mht file
public static String unpackMht(String contentPath) throws IOException {
// dstPath - path where file will be unpacked
String dstPath = openTempDir(null) + File.separator;
String indexFileName = dstPath + new File(contentPath).getName();
try {
Collection<Attachment> attachments = MHTUnpack.unpack(new File(contentPath));
for (Attachment attachment : attachments) {
String filename = attachment.getFileName();
String path = filename == null ? indexFileName : dstPath + filename;
File newFile = new File(path);
if (newFile.exists()) {
newFile.delete();
}
attachment.saveFile(path);
}
return indexFileName;
} catch (MessagingException e) {
throw new IOException(e);
}
}