I'm experiencing an issue while downloading an exe file from within an UWP App. The EXE cannot be run after downloading. When I download it via any browser, it works as expected. My research so far brought me to Alternate Data Streams.
When I download the EXE via any browser, the file gets an ADS like My.EXE:Zone.Identifier:$DATA with ZoneId=3 and some additional stuff inside.
When I download the same file from my UWP, it's also like My.EXE:Zone.Identifier:$DATA, but $DATA is empty with a size of 0 bytes like in the screenshot.
Did anyone experience the same issue and found a solution? Any hint would be great.
EDIT[Code added]:
private async void Download_Click(object sender, RoutedEventArgs e)
{
var uri = new Uri(resourceLoader.GetString("Link"));
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
}
Related
When finding random apk's online through urls, I can successfully download and install them, the user is prompted to ask if they want to install comes up. But when I upload the same apk's to Google drive, and then run the download url from Google drive, the apk's doesn't work. I get a "There was a problem while parsing the package" on the device screen. I put a log to see how much data is being downloaded. And it appears that the apk's being downloaded from google drive are barely the size of what the apk's should be. Around 50k instead of 4MB. I see a lot of questions online about this, but none have talked about Google play not sending the full file. Is there something I'm missing in order to get the full apk downloaded from Google drive? here is the code,
private void downloadApk(){
// checkVersion();
String extStorageDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();
File folder = new File(extStorageDirectory);
folder.mkdirs();
File file = new File(folder, "app-debug.apk");
try {
file.createNewFile();
} catch (IOException e1) {
e1.printStackTrace();
}
DownloadApkTask downloadApkTask = new DownloadApkTask(APKURL,file);
downloadApkTask.execute();
}
public class DownloadApkTask extends AsyncTask<String, Void, Void> {
String fileURL;
File directory;
public DownloadApkTask(String fileURL,File directory) {
this.fileURL = fileURL;
this.directory = directory;
}
#Override
protected Void doInBackground(String... params) {
Log.v("DO in Back started","Started");
try {
FileOutputStream f = new FileOutputStream(directory);
URL u = new URL(fileURL);
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.connect();
InputStream in = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = in.read(buffer)) > 0) {
Log.v("PROGREsS", String.valueOf(len1));
f.write(buffer, 0, len1);
}
f.close();
directory.setReadable(true,false);
} catch (Exception e) {
System.out.println("exception in DownloadFile: --------"+e.toString());
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void stringReturn) {
super.onPostExecute(stringReturn);
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+"/app-debug.apk");
Log.v("STARTING INSTALLATION","-----");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
startActivity(intent);
}
}
Based from this page, parsing error occurs on app installment.
When you try to install an application suddenly a window pop-ups saying "there is a problem parsing the package" which means the application cannot be installed due to apk parser i.e. parsing issue.
There are several reasons why this parsing error occurs & definitely one of them is responsible for your parsing error:
File may be downloaded incompletely.
Application might be not suitable for your hardware or OS version.
Due to security issue settings
Corrupted APK file.
Follow the steps shown below for fixing the android parse error on your mobile devices:
Check Manifested app apk file.
Change the Andriomanifest.xml file to its default setting & also check the name of that file. If the original name of the file is “aap.apk” & if you renamed it as "app1.apk" then also it might cause an error. If you have some knowledge of coding, look into the app code if there is some problem with coding.
Security settings.
For the security purpose, the phone has an inbuilt setting that doesn't allow installing applications from a 3rd party provider other than mobile apps provided by play store. Don’t install an app from the non-trusted website. That might really risk your mobile.
Enable USB debugging.
Go to the settings >> Scroll down then, at last, you will see option “About device” select it.
Look for option “build number.”
Tap on “Build number” for 7 times.
You will see a message “you are now a developer.”
Once you enable to go back to settings
Choose “Developer options.”
Tick mark "USB debugging."
Corrupted App file.
The parse error may cause due to corrupted file too. In this case, download a new but complete APK file, & try again to install it again. This might help you.
Disable Antivirus.
If you have installed applications like antivirus & cleaner apps, then this can also prevent some apps installation. This prevention is due to the safety purpose of the handset. They block suspicious downloads from non-trusted sites. If you really want to install that app then disable the antivirus temporarily.
Clear cache cookies of play store.
Open google play store
Select sidebar & choose option “settings.”
In general settings, you will find out to “clear local search history.”
We are dealing with the code from a course that loads an image. We are trying to do this with an Emulator API 26 Play Store active We have no jpg pictures on the emulator. The Device File Explore will let us Upload a jpg. We have tried various folders with no luck.
Our question is where to Upload the jpg to in the Device File Explore?
Code is Kotlin and the upload method is posted below
fun onChooseImage(view:View){
val intent = Intent()
intent.type = "image/*"
intent.action = Intent.ACTION_GET_CONTENT
val chooser = Intent.createChooser(intent,"Choose Image for Habit")
startActivityForResult(chooser,CHOOSE_IMAGE_REQUEST)
Log .d(TAG,"Image was sent" )
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if(requestCode == CHOOSE_IMAGE_REQUEST && resultCode == Activity.RESULT_OK
&& data != null && data.data != null){
Log.d(TAG,"An Image WAS Choosen")
val bitmap = tryReadBitmap(data.data)
bitmap?.let {
ivIcon.setImageBitmap(bitmap)
Log.d(TAG,"We Updated and Read Bitmap")
}
}
}
private fun tryReadBitmap(data: Uri?): Bitmap?{
return try{
MediaStore.Images.Media.getBitmap(contentResolver,data)
}catch (e:IOException){
e.printStackTrace()
null
}
}
And we are using Cold Boot on the emulator.
We have looked at other posts that suggest you can not use the emulator camera to save pictures to the emulator. Does this mean we need a real device to test this code?
Grendel's answer is workable but I would like to provide a less intensive set of steps
1. Load the app in question
2. Open AVD manager and select the little down icon next to the Emulator your using
3. Click on Wipe Data (suggestion keep Emulator setting Quick Boot) <- other topic
4. Store your jpg in this path Storage->Self->Primary-DCIM
5. This is done by RIGHT click DCIM select Upload navigate to jpg
6. Close AVD manage
7. Run your app and select the same Emulator
It seems with the emulator you need to scan the emulator with Dev Tools BUT one other issue seems to pop up the cache for google play services and google play store needs to be cleared. In the processes of fixing this we tried so many fixes not sure of all the steps in order. As for where to upload the jpg that we are sure of use this path with
/mnt/sdcard/DCIM/water.jpg When you get to DCIM right click it and select Upload
Here is a link that may help HELP LINK
I have developed an Xamarin forms application. Provided download option to download file in our application. I have clicked download file and download progress show in app itself. If lock the iphone while download is in progress and unlock it again download stopped. How can I process download even locked phone?. This occurs only in iOS and works properly in Android.
I have used webclient DownloadFileTaskAsync process to download a file and maintain progress value in it.
WebClient client = new WebClient();
client.DownloadFileTaskAsync(new Uri(DownloadUrl), FileName);
Updated Query:
I have implemented the back-grounding process into my source. I have used "Creating Background-Safe Tasks" concept for my download process. I can download more than one file, so put this process in Task itself previously. Now, I have used BeginBackgroundTask in my download process but download process not carried to UI, even BeginBackgroundTask code doesn't hit while debug the code.
Below function put in native and called this function from forms when click download button.
public async Task DownloadFile(string DownloadUrl, string FileName)
{
var taskID = UIApplication.SharedApplication.BeginBackgroundTask(async() =>
{
WebClient client = new WebClient();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
client.DownloadFileTaskAsync(new Uri(DownloadUrl), FileName);
});
UIApplication.SharedApplication.EndBackgroundTask(taskID);
}
Also registered the app into Background fetch registration categories and now also progress not carried out while lock screen or minimize the app.
Am I missing any process in background techniques? Could you please help me to resolve this or suggest some simple sample as my scenario?
Please help me on this to resolve it.
Regards,
Cheran
You will need to use NSURLSession instead and create a background session for it. You can read how to do this in the official Xamarin Documentation.
You might get away with using WebClient in a background session, but only for a very short time span by using the pattern described in the "Handle iOS Background Limits" docs:
Task.Factory.StartNew(() =>
{
//expirationHandler only called if background time allowed exceeded
var taskId = UIApplication.SharedApplication.BeginBackgroundTask(() => {
Console.WriteLine("Exhausted time");
UIApplication.SharedApplication.EndBackgroundTask(taskId);
});
while(myFlag == true)
{
Console.WriteLine(UIApplication.SharedApplication.TimeRemaining);
myFlag = SomeCalculationNeedsMoreTime();
}
//Only called if loop terminated due to myFlag and not expiration of time
UIApplication.SharedApplication.EndBackgroundTask(taskId);
});
Where you would replace the while with your WebClient code.
However, as mentioned you really need to use Background Transfers for this to work properly.
I'm using WebView to display HTML from a string. This HTML references a stylesheet that I have locally on the device. I'm following the instructions from the official docs so the local CSS file can be accessed. It works fine on Android and iOS but I can't make it work on Windows Phone 8.1. I placed the CSS file in the root of the project and set the build action to Content, then set the BaseUrl to "" (I tried ms-appx-web:/// as well, with no success).
Does anyone know if the docs are missing some instructions? Or is it a bug in Forms? Any help would be appreciated.
Here's the code for populating the WebView with data (in a Forms PCL):
private async Task LoadData()
{
string html = await _dataProvider.GetHtmlAsync("index");
WebView.Source = new HtmlWebViewSource
{
Html = html,
BaseUrl = _baseUrlProvider.Get()
};
}
_baseUrlProvider is an instance of my WebViewBaseUrlProvider that is defined as follows:
internal class WebViewBaseUrlProvider : IWebViewBaseUrlProvider
{
public string Get() => "";
}
EDIT:
Seeing this question leads me to believe that there indeed is a bug in Xamarin Forms. When the link in the HTML contains the whole ms-appx-web:///style.css instead of just style.css, it suddenly starts to work. Obviously, this is not quite cross-platform...
I just found the answer - Xamarin simply ignores the BaseUrl property: https://github.com/xamarin/Xamarin.Forms/blob/2d9288eee6e6f197364a64308183725e7bd561f9/Xamarin.Forms.Platform.WinRT/WebViewRenderer.cs#L26
I'm developing an app for Windows Phone 7 and I'm using a Phonegap template for it.
Everything looks perfect, but now I’m stuck trying to open a PDF file in the browser.
I tried the following but that doesn’t work because the url of the PDF exceeds the 2048 character limit (it’s a data url). This code runs after the deviceReady event was fired.
var ref = window.open('http://www.google.com', '_blank', 'location=no');
ref.addEventListener('loadstart', function () { alert(event.url); });
Now, I'm trying to save the PDF file to storage and then I'm trying to have it opened by the browser, but the browser doesn't show anything. I'm editing the InAppBrowser.cs code from cordovalib and I added the following lines before calling browser.Navigate(loc);
private void ShowInAppBrowser(string url)
{
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
FileStream stream = store.OpenFile("test.pdf", FileMode.Create);
BinaryWriter writer = new BinaryWriter(stream);
var myvar = Base64Decode("the big data url");
writer.Write(myvar);
writer.Close();
if (store.FileExists("test.pdf")) // Check if file exists
{
Uri loc = new Uri("test.pdf", UriKind.Relative);
...
}
}
This code is returning the following error:
Log:"Error in error callback: InAppBrowser1921408518 = TypeError: Unable to get value of the property 'url': object is null or undefined"
I don’t wanna use ComponentOne.
Any help would be greatly appreciated!
You cannot open pdf files from the isolated storage in the default reader for PDF files. If the file is online e.g. it has a URI for it, you can use WebBrowserTask to open it since that will download and open the file in Adobe Reader.
On Windows Phone 8 you actually can open your own file in default file reader for that extension, but I am not sure how that will help you since you target PhoneGap and Windows Phone 7.
Toni is correct. You could go and try to build your own viewer (which would be the same thing as using C1, but with more time involved). I worked on a port of iTextSharp and PDFSharp for WP7, but neither of which are PDF Viewers. They are good for creating PDFs and parsing them some (but to render them there is more work involved). This has been a personal quest of mine, but honestly the best I have gotten is to be able to extract some images from the PDF (and none of the text)
try this
var installedLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;
var assets = await installedLocation.GetFolderAsync("Assets");
var pdf = await assets.GetFileAsync("metro.pdf");
Windows.System.Launcher.LaunchFileAsync(pdf);
This worked correctly on my Device.