=======================
=======================
=======================
출처: http://gwangdroid.tistory.com/59
=======================
=======================
=======================
출처: http://stackoverflow.com/questions/3569313/cant-install-apk-hosted-my-own-apache-server
10
|
It is better if you add the .apk extension to the apache`s mime config. Take a look at this example:https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
You can just find the "apk" record and copy the row to the file /etc/mime.types at your server: application/vnd.android.package-archive apk Also add this to /etc/apache2/mods-available/mime.conf : AddType application/vnd.android.package-archive .apk (There are some other AddType-s, put it after them for sure). From here on you don't have to put anything for the apk`s mime-type in the tag, the server will handle this. ;) UPDATE: fixed a bug in AddType line |
||||
|
7
|
After all I found the problem thanks in part to CommonsWare advise.
Directory where I put apks for downloads is protected by simpe auth. Phone's browser correctly asks (once) for username/password when browsing it but obviously forgets to send auth info when trying to download the file and that causes 401 Unauthorized. Solution: remove basic auth from that dir or use another unprotected dir for the apks. |
||||||||||||||||||||
|
2
|
Use
curl to test the Web server to make sure it is responding to the HTTP request and returning the proper MIME type. Also, example your server logs to see what error is being logged. |
=======================
=======================
=======================
apk를 application/vnd.android.package-archive로 설정하면 됩니다.
CentOS, Fedora등 RedHat 계열의 리눅스에서는 /etc/mime.types 파일을 편집한후
application/vnd.android.package-archive apk
위 라인을 추가하고 apache를 재가동하면 적용됩니다.
=======================
=======================
=======================
출처: http://sdop.egloos.com/3630690
=======================
=======================
=======================
출처: http://blog.naver.com/PostView.nhn?blogId=royalcho&logNo=120195166647
* (정의 및 사용법)
http://mainia.tistory.com/593 (웹페이지에서 스크롤 방지)
http://samse.tistory.com/entry/WebView
http://samse.tistory.com/entry/Using-WebView (App과 웹컨텐츠간 통신방법)
http://blackzaket.blog.me/80114436024
http://blog.naver.com/yell301/130093631952 (goBack, goForward)
2. WebView를 Dialog에 띄우는 방법
http://blog.naver.com/lowmans/100114622708
>>>
3. WebView Zoom
http://blackzaket.blog.me/80114465914
4. WebView와 App 간의 통신
http://blackzaket.blog.me/80114436397
5. 로컬 파일 불러오기
http://blackzaket.blog.me/80114436226
WebView.loadUrl(file://android_asset/<파일명>);
6. WebView를 통한 Apk파일 다운로드 및 설치
http://sdop.egloos.com/3630690
[출처] 웹뷰(WebView)활용2|작성자 조명현
=======================
=======================
=======================
출처: http://www.androidpub.com/2042370
=======================
=======================
=======================
출처: http://www.androidside.com/bbs/board.php?bo_table=b49&wr_id=121447
cocos2d-x 로 만든 다음에 안드로이드 apk 를 만들고 그동안 설치 하는건 문제가 없었는데요.
웹페이지를 통해서 apk를 다운 받고 다운로드상태창(?)에서 다운이 완료된 뒤 설치하려고 하면 실패하네요.
알림에 다운로드가 완료되었다고 나와서 설치하려고 클릭하면 "파일을 열 수 없습니다." 라고 나옵니다.
그러고 난 다음에 알림에서 사라집니다.
파일이 잘못된건가 싶어서 내파일에서 다운로드 폴더로 들어가서 설치하면 문제없이 설치가 됩니다.
웹에서 다운받을때 바로 설치하기 위한 옵션 같은게 있나요?
정확히 말하면 파일을 받고 나서 알림 화면에서 설치하기 위한 방법이요..
안드로이드나 앱은 초보라서 어떤 부분을 설명해야 할지도 잘 모르겠네요..
|
질문자가 자신의 포인트 100 점을 걸었습니다.
답변하시면 포인트 10점을, 답변이 채택되면 포인트 80점 을 드립니다. |
|
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
=======================
=======================
=======================
출처: http://stackoverflow.com/questions/6109304/android-auto-installation-of-apks
2
1
|
I have a webview which basically is capable of intercepting all sorts of links, video, apks, hrefs.
Now, what I want is once I download an APK from a url, that it'll be auto installed: This is part of the shouldOverrideUrlLoading() code:else if(url.endsWith(".apk")) { mWebView.setDownloadListener(new DownloadListener() { public void onDownloadStart(final String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { } }); Intent intent = new Intent(Intent.ACTION_VIEW ,Uri.parse(url)); startActivity(intent); return true; If I add intent.setDataAndType(Uri.parse(url), "application/vnd.android.package-archive"); Than the application crashes... Any ideas as to what to do? EDIT: I was able to initiate a download and an installation of the package automatically (using a sleep() ): else if(url.endsWith(".apk")) { mWebView.setDownloadListener(new DownloadListener() { public void onDownloadStart(final String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { } }); Intent intent = new Intent(Intent.ACTION_VIEW ,Uri.parse(url)); startActivity(intent); String fileName = Environment.getExternalStorageDirectory() + "/download/" + url.substring( url.lastIndexOf('/')+1, url.length() ); install(fileName); return true; and, as vitamoe suggested: protected void install(String fileName) { Intent install = new Intent(Intent.ACTION_VIEW); install.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive"); startActivity(install); } However, I'm unable to capture the exact time that the download is finished, might need to create my own download function and not use the browser's one, any ideas? |
||||||||
|
2
|
To download a file without the browser do sth. like this:
String apkurl = "http://your.url.apk"; InputStream is; try { URL url = new URL(apkurl); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.setDoOutput(true); con.connect(); is = con.getInputStream(); } catch (SSLException e) { // HTTPS can end in SSLException "Not trusted server certificate" } // Path and File where to download the APK String path = Environment.getExternalStorageDirectory() + "/download/"; String fileName = apkurl.substring(apkurl.lastIndexOf('/') + 1); File dir = new File(path); dir.mkdirs(); // creates the download directory if not exist File outputFile = new File(dir, fileName); FileOutputStream fos = new FileOutputStream(outputFile); // Save file from URL to download directory on external storage byte[] buffer = new byte[1024]; int len = 0; while ((len = is.read(buffer)) != -1) { fos.write(buffer, 0, len); } fos.close(); is.close(); // finally, install the downloaded file install(path + fileName); |
||
add comment |
1
|
Due to Android security model it is not possible to install Apk file automatically.
|
||||||||
|
1
|
You can temp. download it to an sd card, install it with the package manager and then remove it again.
protected void install(String fileName) { Intent install = new Intent(Intent.ACTION_VIEW); install.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive"); startActivity(install); } |
||||||||||||||||
|
0
|
why not trying with a download manage and a broadcast receiver that would intercept when download is finished? Download manager works for ANDROID 2.3+ though
Example here: myWebView.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.d("WEB_VIEW_TEST", "error code:" + errorCode + " - " + description); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // handle different requests for different type of files // this example handles downloads requests for .apk and .mp3 files // everything else the webview can handle normally if (url.endsWith(".apk")) { Uri source = Uri.parse(url); // Make a new request pointing to the .apk url DownloadManager.Request request = new DownloadManager.Request(source); // appears the same in Notification bar while downloading request.setDescription("Description for the DownloadManager Bar"); request.setTitle("YourApp.apk"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); } // save the file in the "Downloads" folder of SDCARD request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "SmartPigs.apk"); // get download service and enqueue file DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); manager.enqueue(request); } else if(url.endsWith(".mp3")) { // if the link points to an .mp3 resource do something else } // if there is a link to anything else than .apk or .mp3 load the URL in the webview else view.loadUrl(url); return true; } }); Full answer here: user bboydflo Downloading a file to Android WebView (without the download event or HTTPClient in the code) Broadcast receiver to intercept when download has finished private BroadcastReceiver onDownloadComplete = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { // toast here - download complete } } }; remember to recister recevier in the main activity like this: registerReceiver(onDownloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); |
||
add comment |
=======================
=======================
=======================
출처: http://blog.vogella.com/2011/06/14/android-downloadmanager-example/
Android DownloadManager Example
The Android DownloadManager introduced in Android 2.3. (API 9) is a system service which allows to handle long-running HTTP downloads in the background and notify the triggering application via a broadcast receiver once the download is finished.
Here is a little example for using the DownloadManager. The project will be called “de.vogella.android.downloadmanager” with the activity “DownloadManagerActivity” based on Android API9 or higher.
Change “main.xml” to the following.
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:text="Start Download" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="onClick"></Button> <Button android:text="View Downloads" android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="showDownload"></Button> <ImageView android:layout_height="wrap_content" android:id="@+id/imageView1" android:src="@drawable/icon" android:layout_width="wrap_content"></ImageView> </LinearLayout> |
Change the code of your activity to the following.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
package de.vogella.android.downloadmanager; import android.app.Activity; import android.app.DownloadManager; import android.app.DownloadManager.Query; import android.app.DownloadManager.Request; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.ImageView; public class DownloadManagerActivity extends Activity { private long enqueue; private DownloadManager dm; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { long downloadId = intent.getLongExtra( DownloadManager.EXTRA_DOWNLOAD_ID, 0); Query query = new Query(); query.setFilterById(enqueue); Cursor c = dm.query(query); if (c.moveToFirst()) { int columnIndex = c .getColumnIndex(DownloadManager.COLUMN_STATUS); if (DownloadManager.STATUS_SUCCESSFUL == c .getInt(columnIndex)) { ImageView view = (ImageView) findViewById(R.id.imageView1); String uriString = c .getString(c .getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); view.setImageURI(Uri.parse(uriString)); } } } } }; registerReceiver(receiver, new IntentFilter( DownloadManager.ACTION_DOWNLOAD_COMPLETE)); } public void onClick(View view) { dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); Request request = new Request( Uri.parse("http://www.vogella.de/img/lars/LarsVogelArticle7.png")); enqueue = dm.enqueue(request); } public void showDownload(View view) { Intent i = new Intent(); i.setAction(DownloadManager.ACTION_VIEW_DOWNLOADS); startActivity(i); } } |
Also add the permission to go to the internet to your app.
If you implemented this example you have an Android application which can download my picture (sorry for this ;-)) and allow you to switch to the download manager to see the finished downloads.
Hope this helps.
You find me also on Twitter.
6 Responses to Android DownloadManager Example
=======================
=======================
=======================
DownloadManager
extends Object
java.lang.Object | |
↳ | android.app.DownloadManager |
Class Overview
The download manager is a system service that handles long-running HTTP downloads. Clients may request that a URI be downloaded to a particular destination file. The download manager will conduct the download in the background, taking care of HTTP interactions and retrying downloads after failures or across connectivity changes and system reboots. Instances of this class should be obtained through getSystemService(String)
by passing DOWNLOAD_SERVICE
. Apps that request downloads through this API should register a broadcast receiver for ACTION_NOTIFICATION_CLICKED
to appropriately handle when the user clicks on a running download in a notification or from the downloads UI. Note that the application must have the INTERNET
permission to use this class.
Summary
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
class | DownloadManager.Query | This class may be used to filter download manager queries. | |||||||||
class | DownloadManager.Request | This class contains all the information necessary to request a new download. |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | ACTION_DOWNLOAD_COMPLETE | Broadcast intent action sent by the download manager when a download completes. | |||||||||
String | ACTION_NOTIFICATION_CLICKED | Broadcast intent action sent by the download manager when the user clicks on a running download, either from a system notification or from the downloads UI. | |||||||||
String | ACTION_VIEW_DOWNLOADS | Intent action to launch an activity to display all downloads. | |||||||||
String | COLUMN_BYTES_DOWNLOADED_SO_FAR | Number of bytes download so far. | |||||||||
String | COLUMN_DESCRIPTION | The client-supplied description of this download. | |||||||||
String | COLUMN_ID | An identifier for a particular download, unique across the system. | |||||||||
String | COLUMN_LAST_MODIFIED_TIMESTAMP | Timestamp when the download was last modified, in System.currentTimeMillis() (wall clock time in UTC). |
|||||||||
String | COLUMN_LOCAL_FILENAME | The pathname of the file where the download is stored. | |||||||||
String | COLUMN_LOCAL_URI | Uri where downloaded file will be stored. | |||||||||
String | COLUMN_MEDIAPROVIDER_URI | The URI to the corresponding entry in MediaProvider for this downloaded entry. | |||||||||
String | COLUMN_MEDIA_TYPE | Internet Media Type of the downloaded file. | |||||||||
String | COLUMN_REASON | Provides more detail on the status of the download. | |||||||||
String | COLUMN_STATUS | Current status of the download, as one of the STATUS_* constants. | |||||||||
String | COLUMN_TITLE | The client-supplied title for this download. | |||||||||
String | COLUMN_TOTAL_SIZE_BYTES | Total size of the download in bytes. | |||||||||
String | COLUMN_URI | URI to be downloaded. | |||||||||
int | ERROR_CANNOT_RESUME | Value of COLUMN_REASON when some possibly transient error occurred but we can't resume the download. |
|||||||||
int | ERROR_DEVICE_NOT_FOUND | Value of COLUMN_REASON when no external storage device was found. |
|||||||||
int | ERROR_FILE_ALREADY_EXISTS | Value of COLUMN_REASON when the requested destination file already exists (the download manager will not overwrite an existing file). |
|||||||||
int | ERROR_FILE_ERROR | Value of COLUMN_REASON when a storage issue arises which doesn't fit under any other error code. |
|||||||||
int | ERROR_HTTP_DATA_ERROR | Value of COLUMN_REASON when an error receiving or processing data occurred at the HTTP level. |
|||||||||
int | ERROR_INSUFFICIENT_SPACE | Value of COLUMN_REASON when there was insufficient storage space. |
|||||||||
int | ERROR_TOO_MANY_REDIRECTS | Value of COLUMN_REASON when there were too many redirects. |
|||||||||
int | ERROR_UNHANDLED_HTTP_CODE | Value of COLUMN_REASON when an HTTP code was received that download manager can't handle. |
|||||||||
int | ERROR_UNKNOWN | Value of COLUMN_ERROR_CODE when the download has completed with an error that doesn't fit under any other error code. | |||||||||
String | EXTRA_DOWNLOAD_ID | Intent extra included with ACTION_DOWNLOAD_COMPLETE intents, indicating the ID (as a long) of the download that just completed. |
|||||||||
String | EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS | When clicks on multiple notifications are received, the following provides an array of download ids corresponding to the download notification that was clicked. | |||||||||
String | INTENT_EXTRAS_SORT_BY_SIZE | Intent extra included with ACTION_VIEW_DOWNLOADS to start DownloadApp in sort-by-size mode. |
|||||||||
int | PAUSED_QUEUED_FOR_WIFI | Value of COLUMN_REASON when the download exceeds a size limit for downloads over the mobile network and the download manager is waiting for a Wi-Fi connection to proceed. |
|||||||||
int | PAUSED_UNKNOWN | Value of COLUMN_REASON when the download is paused for some other reason. |
|||||||||
int | PAUSED_WAITING_FOR_NETWORK | Value of COLUMN_REASON when the download is waiting for network connectivity to proceed. |
|||||||||
int | PAUSED_WAITING_TO_RETRY | Value of COLUMN_REASON when the download is paused because some network error occurred and the download manager is waiting before retrying the request. |
|||||||||
int | STATUS_FAILED | Value of COLUMN_STATUS when the download has failed (and will not be retried). |
|||||||||
int | STATUS_PAUSED | Value of COLUMN_STATUS when the download is waiting to retry or resume. |
|||||||||
int | STATUS_PENDING | Value of COLUMN_STATUS when the download is waiting to start. |
|||||||||
int | STATUS_RUNNING | Value of COLUMN_STATUS when the download is currently running. |
|||||||||
int | STATUS_SUCCESSFUL | Value of COLUMN_STATUS when the download has successfully completed. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
long | addCompletedDownload(String title, String description, boolean isMediaScannerScannable, String mimeType, String path, long length, boolean showNotification)
Adds a file to the downloads database system, so it could appear in Downloads App (and thus become eligible for management by the Downloads App).
|
||||||||||
long | enqueue(DownloadManager.Request request)
Enqueue a new download.
|
||||||||||
static Long | getMaxBytesOverMobile(Context context)
Returns maximum size, in bytes, of downloads that may go over a mobile connection; or null if there's no limit
|
||||||||||
String | getMimeTypeForDownloadedFile(long id)
Returns the media type of the given downloaded file id, if the file was downloaded successfully.
|
||||||||||
static Long | getRecommendedMaxBytesOverMobile(Context context)
Returns recommended maximum size, in bytes, of downloads that may go over a mobile connection; or null if there's no recommended limit.
|
||||||||||
Uri | getUriForDownloadedFile(long id)
Returns the
Uri of the given downloaded file id, if the file is downloaded successfully. |
||||||||||
ParcelFileDescriptor | openDownloadedFile(long id)
Open a downloaded file for reading.
|
||||||||||
Cursor | query(DownloadManager.Query query)
Query the download manager about downloads that have been requested.
|
||||||||||
int | remove(long... ids)
Cancel downloads and remove them from the download manager.
|
[Expand]
Inherited Methods
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
|
Constants
public static final String ACTION_DOWNLOAD_COMPLETE
Broadcast intent action sent by the download manager when a download completes.
public static final String ACTION_NOTIFICATION_CLICKED
Broadcast intent action sent by the download manager when the user clicks on a running download, either from a system notification or from the downloads UI.
public static final String ACTION_VIEW_DOWNLOADS
Intent action to launch an activity to display all downloads.
public static final String COLUMN_BYTES_DOWNLOADED_SO_FAR
Number of bytes download so far.
public static final String COLUMN_DESCRIPTION
The client-supplied description of this download. This will be displayed in system notifications. Defaults to the empty string.
public static final String COLUMN_ID
An identifier for a particular download, unique across the system. Clients use this ID to make subsequent calls related to the download.
public static final String COLUMN_LAST_MODIFIED_TIMESTAMP
Timestamp when the download was last modified, in System.currentTimeMillis()
(wall clock time in UTC).
public static final String COLUMN_LOCAL_FILENAME
The pathname of the file where the download is stored.
public static final String COLUMN_LOCAL_URI
Uri where downloaded file will be stored. If a destination is supplied by client, that URI will be used here. Otherwise, the value will initially be null and will be filled in with a generated URI once the download has started.
public static final String COLUMN_MEDIAPROVIDER_URI
The URI to the corresponding entry in MediaProvider for this downloaded entry. It is used to delete the entries from MediaProvider database when it is deleted from the downloaded list.
public static final String COLUMN_MEDIA_TYPE
Internet Media Type of the downloaded file. If no value is provided upon creation, this will initially be null and will be filled in based on the server's response once the download has started.
See Also
public static final String COLUMN_REASON
Provides more detail on the status of the download. Its meaning depends on the value of COLUMN_STATUS
. When COLUMN_STATUS
is STATUS_FAILED
, this indicates the type of error that occurred. If an HTTP error occurred, this will hold the HTTP status code as defined in RFC 2616. Otherwise, it will hold one of the ERROR_* constants. When COLUMN_STATUS
is STATUS_PAUSED
, this indicates why the download is paused. It will hold one of the PAUSED_* constants. If COLUMN_STATUS
is neither STATUS_FAILED
nor STATUS_PAUSED
, this column's value is undefined.
See Also
public static final String COLUMN_STATUS
Current status of the download, as one of the STATUS_* constants.
public static final String COLUMN_TITLE
The client-supplied title for this download. This will be displayed in system notifications. Defaults to the empty string.
public static final String COLUMN_TOTAL_SIZE_BYTES
Total size of the download in bytes. This will initially be -1 and will be filled in once the download starts.
public static final String COLUMN_URI
URI to be downloaded.
public static final int ERROR_CANNOT_RESUME
Value of COLUMN_REASON
when some possibly transient error occurred but we can't resume the download.
public static final int ERROR_DEVICE_NOT_FOUND
Value of COLUMN_REASON
when no external storage device was found. Typically, this is because the SD card is not mounted.
public static final int ERROR_FILE_ALREADY_EXISTS
Value of COLUMN_REASON
when the requested destination file already exists (the download manager will not overwrite an existing file).
public static final int ERROR_FILE_ERROR
Value of COLUMN_REASON
when a storage issue arises which doesn't fit under any other error code. Use the more specific ERROR_INSUFFICIENT_SPACE
and ERROR_DEVICE_NOT_FOUND
when appropriate.
public static final int ERROR_HTTP_DATA_ERROR
Value of COLUMN_REASON
when an error receiving or processing data occurred at the HTTP level.
public static final int ERROR_INSUFFICIENT_SPACE
Value of COLUMN_REASON
when there was insufficient storage space. Typically, this is because the SD card is full.
public static final int ERROR_TOO_MANY_REDIRECTS
Value of COLUMN_REASON
when there were too many redirects.
public static final int ERROR_UNHANDLED_HTTP_CODE
Value of COLUMN_REASON
when an HTTP code was received that download manager can't handle.
public static final int ERROR_UNKNOWN
Value of COLUMN_ERROR_CODE when the download has completed with an error that doesn't fit under any other error code.
public static final String EXTRA_DOWNLOAD_ID
Intent extra included with ACTION_DOWNLOAD_COMPLETE
intents, indicating the ID (as a long) of the download that just completed.
public static final String EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS
When clicks on multiple notifications are received, the following provides an array of download ids corresponding to the download notification that was clicked. It can be retrieved by the receiver of this Intent using getLongArrayExtra(String)
.
public static final String INTENT_EXTRAS_SORT_BY_SIZE
Intent extra included with ACTION_VIEW_DOWNLOADS
to start DownloadApp in sort-by-size mode.
public static final int PAUSED_QUEUED_FOR_WIFI
Value of COLUMN_REASON
when the download exceeds a size limit for downloads over the mobile network and the download manager is waiting for a Wi-Fi connection to proceed.
public static final int PAUSED_UNKNOWN
Value of COLUMN_REASON
when the download is paused for some other reason.
public static final int PAUSED_WAITING_FOR_NETWORK
Value of COLUMN_REASON
when the download is waiting for network connectivity to proceed.
public static final int PAUSED_WAITING_TO_RETRY
Value of COLUMN_REASON
when the download is paused because some network error occurred and the download manager is waiting before retrying the request.
public static final int STATUS_FAILED
Value of COLUMN_STATUS
when the download has failed (and will not be retried).
public static final int STATUS_PAUSED
Value of COLUMN_STATUS
when the download is waiting to retry or resume.
public static final int STATUS_PENDING
Value of COLUMN_STATUS
when the download is waiting to start.
public static final int STATUS_RUNNING
Value of COLUMN_STATUS
when the download is currently running.
public static final int STATUS_SUCCESSFUL
Value of COLUMN_STATUS
when the download has successfully completed.
Public Methods
public long addCompletedDownload (String title, String description, boolean isMediaScannerScannable, String mimeType, String path, long length, boolean showNotification)
Adds a file to the downloads database system, so it could appear in Downloads App (and thus become eligible for management by the Downloads App).
It is helpful to make the file scannable by MediaScanner by setting the param isMediaScannerScannable to true. It makes the file visible in media managing applications such as Gallery App, which could be a useful purpose of using this API.
Parameters
title | the title that would appear for this file in Downloads App. |
---|---|
description | the description that would appear for this file in Downloads App. |
isMediaScannerScannable | true if the file is to be scanned by MediaScanner. Files scanned by MediaScanner appear in the applications used to view media (for example, Gallery app). |
mimeType | mimetype of the file. |
path | absolute pathname to the file. The file should be world-readable, so that it can be managed by the Downloads App and any other app that is used to read it (for example, Gallery app to display the file, if the file contents represent a video/image). |
length | length of the downloaded file |
showNotification | true if a notification is to be sent, false otherwise |
Returns
- an ID for the download entry added to the downloads app, unique across the system This ID is used to make future calls related to this download.
public long enqueue (DownloadManager.Request request)
Enqueue a new download. The download will start automatically once the download manager is ready to execute it and connectivity is available.
Parameters
request | the parameters specifying this download |
---|
Returns
- an ID for the download, unique across the system. This ID is used to make future calls related to this download.
public static Long getMaxBytesOverMobile (Context context)
Returns maximum size, in bytes, of downloads that may go over a mobile connection; or null if there's no limit
Parameters
context | the Context to use for accessing the ContentResolver |
---|
Returns
- maximum size, in bytes, of downloads that may go over a mobile connection; or null if there's no limit
public String getMimeTypeForDownloadedFile (long id)
Returns the media type of the given downloaded file id, if the file was downloaded successfully. Otherwise, null is returned.
Parameters
id | the id of the downloaded file. |
---|
Returns
- the media type of the given downloaded file id, if download was successful. null otherwise.
public static Long getRecommendedMaxBytesOverMobile (Context context)
Returns recommended maximum size, in bytes, of downloads that may go over a mobile connection; or null if there's no recommended limit. The user will have the option to bypass this limit.
Parameters
context | the Context to use for accessing the ContentResolver |
---|
Returns
- recommended maximum size, in bytes, of downloads that may go over a mobile connection; or null if there's no recommended limit.
public Uri getUriForDownloadedFile (long id)
Returns the Uri
of the given downloaded file id, if the file is downloaded successfully. Otherwise, null is returned.
If the specified downloaded file is in external storage (for example, /sdcard dir), then it is assumed to be safe for anyone to read and the returned Uri
corresponds to the filepath on sdcard.
Parameters
id | the id of the downloaded file. |
---|
Returns
- the
Uri
of the given downloaded file id, if download was successful. null otherwise.
public ParcelFileDescriptor openDownloadedFile (long id)
Open a downloaded file for reading. The download must have completed.
Parameters
id | the ID of the download |
---|
Returns
- a read-only
ParcelFileDescriptor
Throws
FileNotFoundException | if the destination file does not already exist |
---|
public Cursor query (DownloadManager.Query query)
Query the download manager about downloads that have been requested.
Parameters
query | parameters specifying filters for this query |
---|
Returns
- a Cursor over the result set of downloads, with columns consisting of all the COLUMN_* constants.
public int remove (long... ids)
Cancel downloads and remove them from the download manager. Each download will be stopped if it was running, and it will no longer be accessible through the download manager. If there is a downloaded file, partial or complete, it is deleted.
Parameters
ids | the IDs of the downloads to remove |
---|
Returns
- the number of downloads actually removed
=======================
=======================
=======================
출처: http://stackoverflow.com/questions/10069050/download-file-inside-webview
I have a webview in my Android Application. When user goes to webview and click a link to download a file nothing happens.
URL = "my url"; mWebView = (WebView) findViewById(R.id.webview); mWebView.setWebViewClient(new HelloWebViewClient()); mWebView.getSettings().setDefaultZoom(ZoomDensity.FAR); mWebView.loadUrl(URL); Log.v("TheURL", URL); How to enable download inside a webview?? If I disable webview and enable the intent to load the url on broswer from application then download works seamlessly. String url = "my url"; Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); Can someone help me out here. The page loads without issue but the link to a image file in the html page is not working.... Thanks in advance for your time. |
|||
add comment |
12
|
Have you tried?
mWebView.setDownloadListener(new DownloadListener() { public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); } }); |
||||||||||||||||||||
|
=======================
=======================
=======================
출처: http://stackoverflow.com/questions/13489120/a-filed-download-doesnt-initiate-from-my-android-app
I am currently building an Android app using HTML5. Inside my app, I am providing link to a HTML file available inside tomcat server on my machine.
<div><a href="http://localhost:8082/directDownload/sample.html">Beep</a></div> The HTML file "sample.html" has link to download a file in same file location, where the sample.html is placed. sample.html has this --> <a href="MyFirstOnMosync.apk">Click to download</a> The problem here is, when I run my app on an android mobile, the link stays dumb and it won't initiate the download from the given path. But, the same URL when I open in a web browser, the download starts. Could anyone let me know why this URL is not initiating the download inside my app?? I already enabled "Allow installation of non-Market applications" in the settings of my android device. |
|||||||||||||||||||||
|
0
|
If you are using real device you must set your url with static ip of your machine like
192.168.0.10 and in emulator 10.0.0.2 See this post. |
||||||||||||||||
|
0
|
Use 10.0.2.2 as IP for server running on the same machine as the Android emulator.
Check out following post with similar problem: Download File inside WebView Check out this link for setting up the mime type in tomcat. Copied for reference: In Tomcat 5.x and 4.x, the default mappings between MIME types and file extensions are stored in the file tomcat_home/conf/web.xml, where tomcat_home is the path under which Tomcat was installed on your server. The mappings specified there are applied to all web / WAP applications hosted on your Tomcat server. Application-specific mappings should be set in the WEB-INF/web.xml file under the directory of your web / WAP application. Each mapping is specified with the <mime-mapping> , <extension> and <mime-type> tags. Here is an example:<web-app> ... <mime-mapping> <extension>xhtml</extension> <mime-type>application/vnd.wap.xhtml+xml</mime-type> </mime-mapping> <mime-mapping> <extension>wml</extension> <mime-type>text/vnd.wap.wml</mime-type> </mime-mapping> <mime-mapping> <extension>wmls</extension> <mime-type>text/vnd.wap.wmlscript</mime-type> </mime-mapping> <mime-mapping> <extension>wbmp</extension> <mime-type>image/vnd.wap.wbmp</mime-type> </mime-mapping> ... </web-app> |
||||||||||||||||||||
|
=======================
=======================
=======================
출처: http://www.dingpong.net/wordpress/?p=214
안드로이드 프로그램에서 자기 자신이나 다른 어플의 apk를 설치시켜야 하는 경우가 존재할 수 있습니다. 이러한 경우 아래 코드를 사용하면 apk 를 설치할 수 있습니다.
Uri apkUri = Uri.fromFile(apkFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType( Uri.fromFile(apkFile), “application/vnd.android.package-archive”);
startActivity(intent);
안드로이드에서 브라우저로 다운받은 apk 파일을 선택하여 설치하는 경우에도 위 코드와 동일한 방법으로 설치가 되는 것으로 파악하고 있습니다. 참고로 시스템 퍼미션으로 구동되는 시스템 애플리케이션에서는 다른 방법으로도 설치가 가능하다고 합니다.
또한 apk를 명령어로 설치, 삭제를 할 수 있는데 방법은 다음과 같습니다.
삭제 : adb uninstall pakeagename
재설치 : adb install -r apkfilename
adb는 sdk안에 tools 폴더에 있습니다. 그러므로 sdk를 다운로드 받아서 사용하셔야 합니다. 환경변수로 폴더를 설정해 두면 어디서나 위 명령어를 사용할 수 있으니 편하게 개발을 할 수 있습니다.
한가지 더 방법으로는 apk 파일이 인터넷에 올려져있다면 안드로이드 폰에 있는 인터넷 브라우저로 해당 url에서 파일을 다운로드 받아서 설치를 하는 것입니다. 다운로드 받은 파일을 클릭하게 되면 설치가 진행 될 것입니다.
- 참고 자료
http://www.androidpub.com/20857
=======================
=======================
=======================
출처: http://stackoverflow.com/questions/2328459/apk-installation-from-web-page
7
|
I'm looking for a sample web page (html code) with a link that will install an apk file directly on my phone by clicking on the link.
|
||
add comment |
15
|
Just link to the apk file in the HTML. It couldn't be any simpler.
<a href="path to my .apk file">link</a> You will have to have "install apps from unknown sources" enabled on your phone. |
||||||||||||||||||||
|
2
|
If you're using ASP.NET, then you'll need to insert the following in your web.config file:
<configuration> ... <system.webServer> <staticContent> <mimeMap fileExtension=".apk" mimeType="application/vnd.android.package-archive" /> </staticContent> </system.webServer> ... </configuration> Apart from that (as others have said), you just need a normal link: <a href="myAndroidApp.apk">Click here</a> and tell your users to enable the Security -> Unknown sources option in Settings. |
||
add comment |
1
|
In .Net this is what I did, I created an
.asmx page then a QR code that pointed to it other wise I kept getting a 404, then this on page load.protected void Page_Load(object sender, EventArgs e){ ViewState["PreviousPage"] = Request.UrlReferrer; string filepath = Server.MapPath("AcsMainMenu.apk"); FileInfo droidfile = new FileInfo(filepath); if (droidfile.Exists) { Response.ClearContent(); Response.AddHeader("Content-Disposition", "attachment; filename=" + droidfile.Name); Response.AddHeader("Content-Length", droidfile.Length.ToString()); Response.ContentType = "application/vnd.android.package-archive"; Response.TransmitFile(droidfile.FullName); Response.Flush(); Response.End(); Response.Redirect(ViewState["PreviousPage"].ToString()); } } |
||||||||
|
=======================
=======================
=======================
'스마트기기개발관련 > 안드로이드 개발' 카테고리의 다른 글
android에서 zip 파일 압축 해제(unzip) (4) | 2014.04.18 |
---|---|
android 안드로이드 개발 다운로드 관련 (0) | 2014.02.27 |
안드로이드 flash 플래시 플레이어 apk 다운로드 관련 (0) | 2014.02.18 |
안드로이드로 android sound 사운드 가 디바이스에 이상하게 들리거나 짤릴때게 들릴 때 관련 (0) | 2014.01.18 |
안드로이드 focus이동 id로 포커스이동 setNextFocusDownId setNextFocusUpId setNextFocusLeftId setNextFocusRightId (1) | 2013.11.01 |
Interesting. I do wonder why it looks like there’s no UploadManager, feels like missing the “Yang” in “Yin and Yang”.
@Casper: Upload depends highly on the receiving side.
@Lars: POST payload vs. GET body and just some slightly different HTTP codes. I’d like if I could just invoke an upload service (picture upload to Flickr, Dropbox sync etc.) without having to handle this is my own heavyweight custom background service.
This code help me solve my download problem. Thank a lot!
Is there any class that i can use for earlier versions of android?
@Muneeb AFAIK you have to use HttpClient directly. For example in a Thread..