downloading android .apk as .zip in android issue - android

I have developed an application,but when my client tries to download the application from the url provided using Samsung GT19003,it is downloading as .zip file and on click of that it says could not open the file error.Whereas it downloads as .apk and works good in our devices.Please help me as how can i resolve the issue.

Make sure that you have set the http Content-Type to application/vnd.android.package-archive
This let the chrome know that it is an application not a zip.

A simple solution is to add the below line in /etc/mime.types
application/vnd.android.package-archive apk
And restart your apache.
This will force browsers to download files as "apk" and not append "zip" to it.

if its being downloaded as .zip
You or your client can use File Expert application to unzip this .zip file it must show .apk file in the unzip folder
give a direct apk link to your user either he/she use default browser to download or use some other like opera and if it is .apk file link then it must be downloaded as is.
you may be using some content site which zip file on particular download methods please ensure it for direct .apk link.
EDIT 1:
Last but not the least .apk is just a zip file so this is not an issue just rename it(From .Zip to .apk) if you could and i hope it will solve the problem

In my case also the issue was same as #alireza-fattahi mentioned regarding the header.
Sharing this here because in our case the file was in Azure Storage and accessed by a CDN in case anyone has the same issue.
Fix for Azure Sorage and CDN
By default the APK blob that was uploaded had content type of application/zip and the same content type reflected in the reposnse header causing the downloaded file to get a .zip extension on Android OS when download was finished.
I had to set a custom rule in the storage CDN to overwrite content-type header in the response to application/vnd.android.package-archive
Remember to purge the CDN cache after you set the new rule
Read more about Azure CDN rules engine.

Here is the Example :
// set your download apk path here
$path= public_path(). "/upload/apk/Ninja11.apk";
//Set header here like this
$headers = [
'Content-Type'=>'application/vnd.android.package-archive',
'Content-Disposition'=> 'attachment; filename="ninja-release.apk"',
];
return response()->file($path , $headers);
This is Laravel framework code but in the same way, you can use in other frameworks. Simply you need to set the Content type
Note : This is not Android side issues

Related

Why after updating file from example.com/.well-known folder is not reflecting changes

I am testing Android Digital Asset Links for deeplinking, uploaded file to example.com/.well-known/assetlinks.json. But once I tested with Project1 successfully. Now I am trying to upload assetlinks.json of another Android project (Project2) to same host (example.com/.well-known/assetlinks.json). But server is not reflecting changes. Also I tried to remove file from server from .well-known folder it still exists in file list if I try to visit example.com/.well-known/
How that can be possible? Is Google webcrawled the file and showing me previous one? Or there are some standards for .well-known folder that once you upload a certificate you cannot change it?
Update
Another problem with this, first I tried with debug:
Then I am trying with Keystore it is giving this error(I already updated code at at server at /.well-known/assetlinks.json path):
Why it is giving error "We could not associate your app with selected domain"

Cannot copying file from Android to Linuxmint 17.3 Desktop "libmtp error: Could not get file from device"

I am trying to copy image file to backup it on my desktop which is linux mint (17.3 or Rosa) installed. I am using Infinix X510 phone with the newest version of android 6. At the beginning it was OK. But, at the end i get the message
“libmtp error: Could not get file from device”
I tried the solution as found by Googling here https://askubuntu.com/questions/879029/libmtp-error-could-not-get-file-from-device-on-attempting-to-transfer-files
But, it wasn't working for me. Is there a way to solve this matter? I need file to support my company job which supplying cosmetics.
Try compressing the file to a compressed format(tar,zip).Copy the file and then decompress it.
Changing the filename was the solution for me e.g: file.mkv to file.zip
Try to rename file, make sure file name not contain (-) (:) etc. Just rename it to alphabet

Corona SDK: system.pathForFile returns nil

This code works in the simulator but not on my Android device:
local path = system.pathForFile("chinese_rules.db")
print("PATH:: " .. tostring( path ) )
When I run this code on my Galaxy S4 path returns nil.
My first thought was that it was some typo (case sensitivity) but I can't find any typo:
http://i59.tinypic.com/wlpu14.png
I can't find any reason why it should receive nil. This causes a problem as I can't load my database.
I have also tried this with the same result:
local path = system.pathForFile("chinese_rules.db", system.ResourceDirectory)
I have been able to load a path and load databases like this before.
Corona Build: 2013.2100 (2013.12.7)
Further reading the documentation I don't see that .db is a restricted file type:
Corona allows direct loading of images and audio files using the
appropriate APIs, but it has limited access to resource files on
Android using the file I/O APIs. Specifically, the following types can
not be read from the resources directory: .html, .htm., .3gp, .m4v,
.mp4,.png, .jpg, and .ttf.
http://docs.coronalabs.com/api/library/system/pathForFile.html
I found out the reason for the problem:
We are two that are working on this project and he had setup to use expansion files so two files was created (the main APK and the OBB expansion file) which I didn't notice and I only loaded the main APK file and I guess the database is in the OBB file. After setting not to use an expansion file the app works.
usesExpansionFile = false

DownloadManager not adding the file extension

I would like to download from my server *.apk file, the file type on the server is *.apk and the MIME is application/vnd.android.package-archive",
when downloading with the DownloadManager the file is downloaded but it creating it without the extension "apk", I tried this
request.setMimeType("application/vnd.android.package-archive");
and still no luck the file created without the extension,
when trying to download it with Chrome it worked perfectly...
please help.
I thought request.setMimeType(..) is used it will add the file extension automatically or Android will recognize the file type,but no... you need to use setDestinationInExternalPublicDir(...)
and set the file extension here....

Cannot download & install app APK from own webpage

I'm trying to have my apps available for download on a website, however, when I upload the APK file, it cannot be found by the browser.
When zipping the APK, it is detected. However, not all phones can install from a ZIP - I have had mixed results.
Why can't I simply upload an APK and have a URL point to it for a download? Why am I getting a 404 and what can I do to avoid it?
Why can't I simply upload an APK and have a URL point to it for a download?
You can. Plenty of people do it. There are entire Web sites dedicated to doing it, albeit usually with pirated content.
Why am I getting a 404
Because the URL you are entering into the browser is not the URL where the file is at on the server. This is the cause of approximately 100% of 404 errors, across the Internet, regardless of circumstance.
what can I do to avoid it?
Use the proper URL. Also, be sure to set the server's MIME type configuration map to serve up your file as application/vnd.android.package-archive.
This is what i did in my asp.net application
My Application hosted under Window server 2008r2 having IIS 7
Step 1: In .aspx page add hyperlink set navigateurl as file path
<asp:HyperLink ID="lnkdwnload" runat="server" NavigateUrl="~/Application_Android/MyAndroidAppAame.apk">Download MyApp</asp:HyperLink>
Step 2: Web.config add mimeMap element under staticContent
<system.webServer>
<staticContent>
<mimeMap fileExtension=".apk" mimeType="application/vnd.android.package-archive"/>
</staticContent>
</system.webServer>
in case you are using .net core,
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
...
var provider = new FileExtensionContentTypeProvider();
// Add new mappings`enter code here`
provider.Mappings[".apk"] = "application/octet-stream";
app.UseStaticFiles(new StaticFileOptions()
{
ContentTypeProvider = provider
});
}
Upload a web.config file in the directory where you keep the apk file
The content of the web.config should be :
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".apk" mimeType="application/vnd.android.package-archive" />
</staticContent>
</system.webServer>
</configuration>
Now you can download the apk file..
Thanks it is working
This is what i did in my asp.net application
My Application hosted under Window server 2008r2 having IIS 7
Step 1: In .aspx page add hyperlink set navigateurl as file path
<asp:HyperLink ID="lnkdwnload" runat="server" NavigateUrl="~/Application_Android/MyAndroidAppAame.apk">Download MyApp</asp:HyperLink>
Step 2: Web.config add mimeMap element under staticContent on same path
<system.webServer>
<staticContent>
<mimeMap fileExtension=".apk" mimeType="application/vnd.android.package-archive"/>
</staticContent>
In Window Server go to IIS Manager, select your virtual directory and select MIME type
Add new MIME type -> Extension "apk" Type -> "application/vnd.android.package-archive .apk"
be sure add .apk extention
It will enable the apk file to download from Windows Server.

Categories

Resources