I need to run a command from windows store app?
the command is something like this : java -jar abc.jar
How can I do that?
EDIT :
I tried this but with no luck. It says file not found.
string exeFile = #"C:\DATA\start.bat";
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(exeFile);
if (file != null)
{
// Set the option to show the picker
var options = new Windows.System.LauncherOptions();
options.DisplayApplicationPicker = true;
// Launch the retrieved file
bool success = await Windows.System.Launcher.LaunchFileAsync(file, options);
if (success)
{
// File launched
}
else
{
// File launch failed
}
}
The app container blocks this behavior for Store apps.
First of all, you're attempting to obtain a StorageFile through your package InstalledLocation folder, which will not work. InstalledLocation is a StorageFolder, and its GetFileAsync looks for files only within that immediate folder. This is why it's returning file not found.
The API that takes an arbitrary path is Windows.Storage.StorageFolder.GetFileFromPathAsync. However, your ability to access files is limited by the app container. You can access files in your package folder or app data locations by default, or the various media libraries if you've declared access in the manifest, but otherwise you have to go through the file picker so the user is aware of what you're doing and can grant consent. Simply said, this is the only way you'll get to a file in a location like c:\data. You can play with this using Scenario 1 of the Association launching sample and the "Pick and Launch" button.
If you can get that access permission, then in you'll be able to launch a file if it's not a blocked file type. Data files (like a .docx) that are associated with another app work just fine, but executables are wholly blocked for what should be obvious security reasons. You can try it with the sample I linked to above--pick .bat, .cmd, .exe, .msi, etc. and you'll see that LaunchFileAsync fails.
Also note that the other launcher function, LaunchUriAsync, also blocks file:/// for the same reasons.
Related
I created a mobile html5 web with the playframework 2.x. Users are able to upload images via the app, which then are stored on the server the app is running on.
Images are stored in public/imagesand acessed like this: #routes.Assets.at(images/images1.jpg)
My problem is that whenever a user is uploading an image to my server and then is trying to view the uploaded image afterwards, the image can`t be displayed.
I found out that whenever I restart the play process on the server, then the newly uploaded image will be displayed correctly. I normally start my production server like this:
activator dist
and afterwards unzip the created zip directory and run the generated script.
I figured that the problem is that when the app is packed it will only pack the assets available at the time in the assets.jar and therefore not be able to show new images which are added after the server is started.
So my question is, what do I need to change so that images, which are changed or added while the server is running are displayed correctly, without having to repack and restart the app.
My routes file
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
# Home page
GET / controllers.Application.index
# Used in Javascript to push new User into Database via Ajax
PUT /users/:i controllers.Userdata.addUser(i: Int)
... similiar PUT Requests ...
PUT /deactUser/:i controllers.Userdata.deactUser(i: Int)
GET /reloadUsers controllers.Userdata.reloadUsers(minA: Int, maxA: Int, gend: String, orient: String, verf: String)
GET /ads controllers.Application.getAds()
# Javascript Router
GET /assets/javascripts/routes controllers.Application.javascriptRoutes()
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
After creating dist package the public folder is accessed from created *.jar file, therefore you need to re-dist your app to make uploaded files available in it.
Instead you should create some directory in filesystem and define its path (preferably via configuration file), so you will upload files and serve them into/from independent location. Of course you'll need to write custom action to serve them as well, but that's just several lines of code.
Here's what to implement in practise:
In your routes file, add something like this:
GET /customImage/:name controllers.Application.imageAt(name:String)
Then implement imageAt like this:
public Result imageAt(String imageName) throws FileNotFoundException {
File imageFile = new File("/path/to/image"+imageName);
if (imageFile.exists()) {
String resourceType = "image+"+imageName.substring(imageName.length()-3);
return ok(new FileInputStream(imageFile)).as(resourceType);
} else {
return notFound(imageFile.getAbsoluteFile());
}
}
And that's it. Anything you put to "/path/to/image" will be accessible via url /customerImage/
They can also be accessible via revert routes like #routes.Application.imageAt(imageName)
I'm creating an flash app where users can select something and download a temple. I'm publishing this file using air application with runtime embedded. In the app I've included a folder called documents with the individual files the user can download. Currently I'm using navigateToURL but I don't want it to rely on the browser. I've also tried this:
function surveyDownload(evt:MouseEvent):void {
var request = new URLRequest("document/template.docx");
var localRef = new FileReference();
try
{
// Prompt and download file
localRef.download( request );
}
catch (error:Error)
{
trace("Unable to download file.");
}
}
but all I get is the trace statement "Unable to download file".
How can I download an embedded file without the browser?
Your question is a little unclear. You want the user to download something from a server? If so then document/template.docx is not a URL so of course that will not work.
If you are talking about copying a file out of the AIR app bundle to the user's hard drive then you don't need URLRequest but rather the methods in the File class (browseForSave and copyTo).
Read the docs for File and search out some tutorials – there are loads and more complete than I would write here.
In WP8, I'm opening a file (pdf) with the following method:
bool success = await Windows.System.Launcher.LaunchFileAsync (docfile);
but the method always returns 'true' (whether or not any app to open the file).
How can I check before making the asynchronous call to open the file, if there is certainly any app to open this kind of file (eg extension pdf)?
i have a question
i want to know how can i open downloaded file in my app (like when you download .PDF File in Internet Explorer it shows apps that can open .PDF files )
please help me snippet of codes !
first you have to save your file in isolated storage and you need to use launcher this code would help you:
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
// Access the bug query file.
StorageFile yourfile = await local.GetFileAsync("Pradeep.pdf");
// Launch the bug query file.
Windows.System.Launcher.LaunchFileAsync(yourfile);
}
this launcher is available in windows phone 8 only.
As stated in MSDN :
"You can use file and URI associations in Windows Phone 8 to automatically launch your app when another app launches a specific file type or URI scheme. When launched, a deep link URI is used to send the file (a reference to the file) or URI to your app."
Basically you need to do following steps :
Register your application to be associated to a specific file type, for example .pdf file extension in this case. This step done by adding <Extension> in WMAppManifest.xml.
When your application get launched upon user opening a .pdf file, get file id from query string then get the physical file using SharedStorageAccessManager based on file id.
The rest is to handle opening the file in your application.
I found this very nice blog explaining the detail of every steps, accompanied with downloadable source code.
PART I: explaining background concept and creating application to launch associated file
PART II: explaining details of step 1-3 above with sample application
I am not able to access C:\Users\Public\Documents folder from Windows store app running on a x86 machine using StorageFolder.GetFolderFromPathAsync("C:\Users\Public\Documents"). It works fine on my win8 desktop. any idea why I get this error?
Thanks,
MetroUI.
You can't access the file system outside your apps sandbox using that method. That will only access files in your apps isolated storage.
If you want to get files from outside the sandbox you will have to use a FileOpenPicker and have the user select the file
var picker = new FileOpenPicker();
picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
var file = await picker.PickSingleFileAsync();
if (file != null)
{
IRandomAccessStream stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
}
Then you would work with the data in the stream.
J.B is right, you can't access that folder directly due to sandbox limitations, but there are 2 other approaches you can take that might suite you better.
If you Add Documents Library to your app's Capabilities, you will be able to access the files in user's Documents library directly (it should include Public Documents as well, unless the user changed his settings), as long as you have declared a File Type Association for that extension to your app's Declarations. You can set both by editing Package.appxmanifest. Use the following code to access the StorageFolder:
var folder = KnownFolders.DocumentsLibrary;
Keep in mind that you need a company account to publish apps with Documents Library capability to Windows Store.
Alternatively you can use FolderPicker so that the user will grant you access to that folder. In this case you don't need any capabilities or declarations and you will be able to access all files:
var picker = new FolderPicker();
picker.FileTypeFilter.Add(".txt");
var folder = await picker.PickSingleFolderAsync();
You don't need the user to select the folder every time the app starts. You can store its reference to FutureAccessList to access it later and store the corresponding token (e.g. to settings):
var token = StorageApplicationPermissions.FutureAccessList.Add(folder);
When you want to access the folder again just use the token to get the folder reference:
folder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(token);
var items = await folder.GetItemsAsync();