简体   繁体   English

下载.apk文件时打开android软件包安装程序

[英]Open android package installer upon download of .apk file

Is there any way to signal Android OS to open the package installer upon download of an .apk file? 有没有办法通知Android OS在下载.apk文件时打开软件包安装程序?

Perhaps by Content-Type? 也许是Content-Type? or maybe an APK specific url protocol, like apk://apk.location ? 或者可能是一个APK特定的url协议,比如apk://apk.location

Are you doing the download yourself in your own app, or are you trying to create some behavior in an external app? 您是在自己的应用程序中自行下载,还是在外部应用程序中创建某些行为?

I don't think you'll be able to trigger behavior upon download outside of your app (since the user would have to select the downloaded file in order to open it), but if you're handling the download yourself, I think you want this post on how to install an application programmatically. 我不认为您可以在应用程序外部下载时触发​​行为(因为用户必须选择下载的文件才能打开它),但是如果您自己处理下载,我认为您想要这篇关于如何以编程方式安装应用程序的帖子。

Edit: Addressing your comment in which you said you are writing a website and want to be able to force the APK to be opened by a native app: I can think of a way to do something like it, but you would have to handle the download in the native app because you won't get the browser to do the download for you. 编辑:解决你的评论,其中你说你正在写一个网站,并希望能够强制APK由本机应用程序打开:我可以想办法做类似的事情,但你必须处理在本机应用程序中下载,因为您无法让浏览器为您进行下载。

You'll need to register your native app to receive ACTION_VIEW Intent s with URIs in whatever format you choose; 您需要注册您的原生应用程序,以便以您选择的任何格式接收带有URI的ACTION_VIEW Intent ; I recommend using something like yourappname://localhost/escaped_download_url_to.apk . 我推荐使用像yourappname://localhost/escaped_download_url_to.apk这样的东西。 In your Activity get the path from the URI in the Intent and grab the last part of it (URI handling is broken into a few components: protocol, host, and path). 在您的Activity ,从Intent的URI获取路径并获取它的最后一部分(URI处理分为几个组件:协议,主机和路径)。 Unescape it as necessary and then start the download manually in the app, and then upon completion you open the downloaded APK from wherever your app put it, using the link I provided. 根据需要进行Unescape,然后在应用程序中手动开始下载,然后在完成后,使用我提供的链接从您的应用程序放置的任何地方打开下载的APK。

So long as you make sure your mobile website provides an href to yourappname://localhost/escaped_download_url_to.apk , you'll be able to trigger this behavior. 只要您确保您的移动网站为yourappname://localhost/escaped_download_url_to.apk提供了一个href ,您就能够触发此行为。 When the user clicks that link, it should provide a dialog to choose which app to use to open it (if they have more than one app capable of doing so) which when they select your app will launch the Activity that you registered with the Intent filter. 当用户单击该链接时,它应该提供一个对话框来选择用于打开它的应用程序(如果他们有多个应用程序能够这样做),当他们选择您的应用程序时将启动您使用Intent注册的Activity过滤。

Edit the second: you probably don't need to do any escaped URIs; 编辑第二个:您可能不需要执行任何转义的URI; just using a made-up URI protocol as you suggest in your own post should work, so long as your app registers to receive Intents with that protocol. 只要您的应用程序注册接收具有该协议的Intent,只需使用您在自己的帖子中建议的伪造的URI协议即可。 yourappname://yourserver.com/my/location.apk will work. yourappname://yourserver.com/my/location.apk可行。 All that really matters is being able to pull the download URL out of the data you give to the app in the URI. 真正重要的是能够从URI中提供给应用程序的数据中提取下载URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在Android中通过Package Installer安装apk文件? - Failed to install apk file by Package Installer in Android? android app下载apk文件并打开(安装) - android app download apk file and open it (to install) 在 chrome 下载列表中打开 apk 未打开 apk 安装程序 - opening apk in chrome download list not open the apk Installer Android APK 安装“软件包安装程序已停止” - Android APK Installation "Package Installer has Stopped" 在手机上自动下载并打开.APK文件 - Download and open .APK file automatically on Mobile 通过DownloadManager下载后打开apk文件 - Open apk file after download via DownloadManager Android套件管理员-安装并开启APK - Android package manager - install and open APK 我正在 flutter 中制作一个 .XAPK 安装程序应用程序。使用 open_file package 我可以打开 normal.apk 安装对话框,但如何安装.XAPK - I am making an .XAPK installer application in flutter. with open_file package I can open normal .apk installation dialogue but how can I install .XAPK Android:将.apk文件上传到服务器,但无法下载该.apk文件 - Android : uploaded .apk file to server but cant download that .apk file Android下载apk文件并保存到内部存储 - Android download apk file and save to INTERNAL STORAGE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM