[英]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.