Android :: Best Practice For Downloading File - URLConnection - HttpClient - Intent

Mar 11, 2010

If an app needs to download some critical data (without the data it cannot function) of several MB, what is the best practice? The app would start, a prompt would be shown to confirm download, download would commence, and the user would be prevented from going further until the download successfully completes. I don't expect the download would take more than, say, 10 secs over wifi but, of course, would take much longer over 2G. Is a service absolutely essential for this? Maybe there is already some code out there that takes a URL, downloads it in a service, and broadcasts a configurable Intent when the download has completed?

Android :: Best practice for downloading file - URLConnection - HttpClient - Intent


Android :: Best Practice - Passing Id To New Intent?

Sep 22, 2009

I am creating a database driven app for managing people. I am showing a list of people with each name in a TextView. When a TextView is clicked, I launch a new intent to show the detail for the person. My question: What's the best practices for passing the id of the person to the new intent? The TextView is displaying the name of the person, so how do I know the id of the person? Once I know the id, I know how to pass it to the new intent, but I don't know what the best way to associate the id of the person to the TextView. Is there a best practice for this?

View 2 Replies View Related

Android :: Apache HttpClient In Android Extremely Slow Downloading Attachment

Aug 1, 2010

I am trying to download a zip file using HttpCLient 4 and it is going at around .5 (kilobytes/kilobits)? per minute. The file is less than a MB large, and the download will probably take an hour! Am I doing something wrong? How else should I do this?

Here is my current implementation:

CODE:..................

View 1 Replies View Related

Android :: Uploading A File With HttpClient And HttpPost

Nov 9, 2009

I'm working on an application that does an upload to a webserver, but struggling with the actual fileupload.. code:

CODE:............

Now, I have this working with what is no longer supported in MultipartEntity as follows:

CODE:...........

Problem is MultipartEntity is apparently no longer supported, although I found the libraries I can include in my project.

View 12 Replies View Related

Android :: Import Org.apache.commons.httpclient.HttpClient Library Error

Jul 2, 2009

I got one blog which interacts with servlets... Link as follows

http://groups.google.com/group/android-developers/browse_thread/threa...

In that program 2 libraries were used..

1---> import org.apache.commons.httpclient.HttpClient; 2---> import org.apache.commons.httpclient.methods.GetMethod;

When i check these libraries in my program, its show error....how to resolve this error?

View 11 Replies View Related

Android :: How To Pass The Parameters To The Urlconnection In Java

Mar 13, 2010

I can establish a connection using HttpUrlConnection.

My code below.

CODE:....................

Getting filenotfound exception. dont know why?

How to pass username and passwrod parameter to the url by code..

View 2 Replies View Related

Android :: Get The Size Of File Before Downloading?

Jun 6, 2010

I have to download a file and I'm using this code, which is basically an AsyncTask that is meant to update a progress bar. But, since I don't know what's the file size I've been having to use the spinner progress bar. So, how can I get the file size before start downloading it so that I can use a normal progress bar?

View 1 Replies View Related

Android :: How To Handle Switch From 3G To WIFI - UrlConnection TimeOut

Nov 16, 2010

My Application needs to Download some bigger Files. I use a Service for the Download an show the Progress in a Notification. The Problem is that during that download time the user can switch from 3g to WIFI. In that case the progress stops but no exception is thrown.

How do i handle this situation properly?

CODE:.................

View 1 Replies View Related

Android :: Downloading File From Web Server Programmatically

Nov 11, 2009

i am downloading files from web server programatically. after download is complete, i checked the file.the size ,extension and all other parameters are correct but i when i try to play that file in media player it is showing that it is corrupt.

byte[] b = null; InputStream in = null; b = new byte[Integer.parseInt(size)]; // size of the file. in = OpenHttpConnection(URL); in.read(b); in.close();
File folder = new File("/sdcard", "folder");
boolean check = folder.mkdirs();
Log.d("HttpDownload", "check " + check);
File myFile = new File("/sdcard/folder/" + name);
myFile.createNewFile();
OutputStream filoutputStream = new FileOutputStream(myFile);
filoutputStream.write(b);
filoutputStream.flush();
filoutputStream.close();

View 2 Replies View Related

Android :: WebView Displays .pkg File Instead Of Downloading It?

Oct 14, 2010

I run a site that offers .pkg files to my users for download to there device. The issue is instead of downloading the .pkg file it just displays the raw code of the .pkg file in the webview. How can I get this to force download to the root of the sd card? Here is what I have

package com.ps3brew.view;
import com.ps3brew.view.R;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class WebViewExample extends Activity {..........................

View 2 Replies View Related

Android :: Displaying Progress Bar While Downloading File

Nov 9, 2010

I have been searching for days trying to find solution to my problem. I would like to show a progress bar while downloading a file in Android. I found enough to download the file but have struggled to figure out how to display a progress bar.

Here is my download code:...............

View 2 Replies View Related

Android :: File Downloading With Service In Background

Nov 14, 2010

When I download a file from web in android, then I want to show a progress bar in notification area of status bar through service, but I am not able to do this. How can i do it? I am not able to pass the file length in service. I am giving URL in EditText, and I am clicking Download Button. After Click A class will be called on Click Listener, this class is having a function. In that function I am doing processing or functionality of downloading, Now I want to show the progress bar in Notification Area Through service, but I can not able to do this.

View 2 Replies View Related

Android :: Downloading File From URL Extremely Slow

Mar 19, 2010

I've got the following code:

BufferedInputStream stream = new BufferedInputStream(new URL("my url that points to a binary file").openStream(), 1024 * 1024); BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(downloadFile)); byte buf[] = new byte[1024 * 1024]; int numBytesRead; do { numBytesRead = stream.read(buf); if (numBytesRead > 0) { fos.write(buf, 0, numBytesRead); } } while (numBytesRead > 0);

View 4 Replies View Related

Android :: When Connect By Code With UrlConnection Get: User-Agent - Unavailable

Sep 15, 2009

I have found an issue. I have a server that uses User Agent header to identify the device that is connecting to it. But when i connect to the server using HttpURLConnection i get no User Agent header, but when i connect with the browser it sends the correct User Agent.

For testing i am using an echo server that replies with the headers it found on the request.

When i connect with browser i get: eg: User-Agent: Mozilla/5.0 (Linux; U; Android 1.5; en-fr; HTC Hero Build/CUPCAKE) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1 Up.Link/6.3.1.20.06.3.1.20.0.

But when i connect by code with UrlConnection i get: User-Agent: UNAVAILABLE.

Does anyone know we i get different behaviors? How i can i connect in the same way the browser does?

View 4 Replies View Related

Android :: Read Data From Text File Without Downloading It?

Oct 27, 2010

Is there a way to do it within an app without downloading the file first? Somehow stream the text content?

View 1 Replies View Related

Android :: Php Headers For .apk File Not Working When Downloading On Phone

Jul 29, 2010

I am trying to download an Android APK file that is output by a php page. I have the following and it works on firefox but not on the phone. Firefox downloads with an apk extension but has a little firefox icon next to it. The phone downloads the file with a .html extension, why is this?

UPDATE: Full source

function display($tpl = null) {
//SETUP
$appId = JRequest::getInt('id', '0');
$model = &$this->getModel();

$app = $model->getApplication($appId);.................

View 2 Replies View Related

Android :: Open Apk File After Downloading For Auto Update?

Aug 25, 2010

I have an application that I'd like to add auto-update functionality (its not in the marketplace). I have all the code in place that would check to see if there is an update available and then i call something like this: Intent intent = new Intent(Intent.ACTION_VIEW ,Uri.parse(Configuration.APK_URL)); c.startActivity(intent); which starts downloading the file, although is there a way that I can programatically tell it to "open" the file to begin the installation process without the user having to go to the downloads and clicking on it?

View 1 Replies View Related

Android :: Open A Local App File In Another App Via An Intent

Nov 8, 2010

I don't want to store said file on the sdcard in this case. The file also cannot be storage directly in the apps local files directory. It needs to be in a subdirectory, so it cannot write the file using openFileOutput() and MODE_WORLD_READABLE.

The app may download files small files like pdfs and store them locally in a subdirectory. I would like to be able to have the user open these files if they have an app that can open them.

For example here is an intent for sending a pdf:

CODE:..............

path being something like: /data/data/packagename/files/subdir/example.pdf

That intent will open a pdf viewer, but the viewer is unable to open the file. I assume this is a permissions issue. I tried Mark Murphy's suggestion here: http://groups.google.com/group/android-developers/browse_thread/thread/4e55d869213483a9/b7270078ac1a2744?lnk=raot of using Runtime.getRuntime().exec("chmod 755 " + fileName); but it didn't make any difference. He also suggested a Content Provider but I would like to avoid it if I can because it seems like a lot just to get this file over to another app.

If the content provider is the only option, do I have to save the file to the content provider or can I just use the content provider as a pass through to get it to the other app when I need to?

View 2 Replies View Related

Android :: Intent Definition In Manifest File

Sep 26, 2010

I would like to start my own SMS editor when user selects "Send message" from contacts application. How do I define intent in manifest file to allow passing contact details to the editor?

View 1 Replies View Related

Android :: URLConnection.getOutputStream - Working Fine In Java Main But Not In Activity

Feb 25, 2009

URLConnection conn = url.openConnection(); in debug stack the value of conn is like this

debug stack:---------------------------------------

when i click on conn, it shows me this value

org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection:http:// www.myweb.com/api/bin/validate.php

some of the childs of conn are as below

chunklength=-1 connected= false connection= null host address= null httversion=1 ------------------------

java code:

CODE:..............

View 2 Replies View Related

Android :: Call .apk File Of PDF Viewer Through Intent Of Application?

Mar 13, 2010

I have only .APK file of PDF Viewer and my requirement is to use pdf viewer for reading document called through Web API . Is there any possibility to integrate these two in same package apart from source code?

View 1 Replies View Related

Android :: Retrieving File Path When Using Intent Filter

Oct 5, 2010

I realise one has to use an intent filter to associate a file format with an application, but once this is done how does the app 'receive' the path to the file that was chosen? Is there a special method it calls on the Activity?

View 2 Replies View Related

Android :: Custom Changeable Handler When Service Finishes Downloading File

May 30, 2010

I have a Service that downloads a file from the internet. What I want is for the response (an InputStream in this case) to be handled by a custom handler that can be switched (like a strategy pattern) but I can't figure out how to do this. So basically the User of the API would be able to plug in different handlers for the response, some would parse XML, others might save files etc. I realise I could pass through the activity context and execute the method from this (given some interface) but I don't want to do this obviously, in case the Activity is closed in the meantime while the file is still downloaded.

UPDATE - I just had one idea it will work sort of but has problem if the DownloadRunnable gets changed between executions of the downloads.

The modified Runnable interface
interface DownloadRunnable {
void run(InputStream stream);
}

An enum

public enum ServiceHandler {.......................

View 1 Replies View Related

Android :: Make SAX Parser Wait For File To Finish Downloading Before Parsing?

Sep 20, 2010

I am having a problem where my XML files are slow to load and don't finish downloading before they start to be parsed which throws an xml not well formatted exception from my parser showing that the file downloaded incompletely. The complete error from logcat is "ERROR/Error(323): errororg.apache.harmony.xml.ExpatParser$ParseException: At line 10, column 46: not well-formed (invalid token)" I know the xml file is correct because sometimes it will work and I can also pull it up in my browser and look at it.

What would be the best way to make the parser wait for the InputSource before continuing on and parsing the xml data? The code below is the code I use to get the file and parse it.

SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
GradeHandler gradeHandler = new GradeHandler();
xr.setContentHandler(gradeHandler);
URL url = new URL("https://url/to/xml/file");
HttpsURLConnection ucon = (HttpsURLConnection)url.openConnection();
ucon.setHostnameVerifier(new AllowAllHostnameVerifier());
xr.parse(new InputSource(new BufferedInputStream(ucon.getInputStream())));

View 1 Replies View Related

HTC EVO 4G :: Data Time Out - Downloading File From Android Marketplace Surfing Web Watching Using GPS?

Jun 25, 2010

I have been having some major problems with my EVO regarding the data. If I use anything that is on the heavy side of bandwidth, like downloading a file from android marketplace, surfing the web, watching sprint tv, using the GPS, etc...the data will just time out for about 3 min at a time. For instance if I am downloading a 5mb app from android marketplace, it will maybe download a megabyte, then it will just stop downloading. If you look at the 3G symbol at the top, it will be white, but only the upstream indicator will be on. I can then open any other internet application on the phone, and nothing will work. It usually lasts for about 3 minutes at a time and happens fairly regularly. It will end up taking me 15-20 min to download a 5mb file from the marketplace. Same thing if I browse a bandwidth heavy site like digg.com. It will just time out after a while and it will just show the upstream indicator as solid and not do anything in any program.

This problem is not location dependent. I have this issue at my apartment, at work, at my friend's house, at the Sprint store...anywhere. I live in South Denver.

In chronological order, this is what I have done to troubleshoot/fix the problem:

First noticed problem
Turned off phone/Turned back on
Rooted and installed custom version of 2.1 w/ Sense
Removed battery (power cycle)
Talk to Sprint cust care. They sent signal over that reactivated the phone (2x)
Did factory reset on phone and formatted SD card
Swapped phone at Sprint store with new one

So even after swapping my EVO with a new EVO from the Sprint store and not fooling with the phone at all, I am still having the same exact issue.

I am absolutely at wit's end with this and I have no idea what to do at this point.

Update (6/25):

I have not been able to test with Wifi yet, but I just had one of my coworkers that has the same phone to replicate the issue on his phone. He is having the same exact problem as me, he just didnt realize it.

We set our phones next to each other and downloaded Space Buster 3D Lite off the Android Marketplace. Mine crapped out about 2mb in and so did his. He wasnt able to surf or do anything else on his phone for a few minutes just like mine.

I'm wondering if this a network problem in our area or if there is a problem with the phone.

Also, I downloaded a continuous ping program and did 3,000 pings with no packet loss, so it seems to only happen with heavy data usage ie. saturating your bandwidth.

View 16 Replies View Related

Android :: Launching Intent Not Working On Saved Image File

Jun 2, 2010

First of all let me say that this questions is slightly connected to another question by me. Actually it was created because of that. I have the following code to write a bitmap downloaded from the net to a file in the sd card:

// Get image from url
URL u = new URL(url);
HttpGet httpRequest = new HttpGet(u.toURI());
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
InputStream instream = bufHttpEntity.getContent();
Bitmap bmImg = BitmapFactory.decodeStream(instream);
instream.close();

// Write image to a file in sd card
File posterFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Android/data/com.myapp/files/image.jpg");
posterFile.createNewFile();
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(posterFile));
Bitmap mutable = Bitmap.createScaledBitmap(bmImg,bmImg.getWidth(),bmImg.getHeight(),true);
mutable.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();

// Launch default viewer for the file
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(posterFile.getAbsolutePath()),"image/*");
((Activity) getContext()).startActivity(intent);

A few notes. I am creating the "mutable" bitmap after seeing someone using it and it seems to work better than without it. And I am using the parse method on the Uri class and not the fromFile because in my code I am calling these in different places and when I am creating the intent I have a string path instead of a file. Now for my problem. The file gets created. The intent launches a dialog asking me to select a viewer. I have 3 viewers installed. The Astro image viewer, the default media gallery (I have a milstone on 2.1 but on the milestone the 2.1 update did not include the 3d gallery so it's the old one) and the 3d gallery from the nexus one (I found the apk in the wild). Now when I launch the 3 viewers the following happen:

Astro image viewer: The activity launches but I see nothing but a black screen.
Media Gallery: I get an exception dialog shown "The application MediaGallery (process com.motorola.gallery) has stoppedunexpectedly. Please try again" with a force close option.
3D gallery: Everything works as it should.

When I try to simply open the file using the Astro file manager (browse to it and simply click) I get the same option dialog but this time things are different:
Astro image viewer: Everything works as it should.
Media Gallery: Everything works as it should.
3D gallery: The activity launches but I see nothing but a black screen.

As you can see everything is a complete mess. I have no idea why this happens but it happens like this every single time. It's not a random bug. Am I missing something when I am creating the intent? Or when I am creating the image file? As noted in the comment here is the part of interest in adb logcat. Also I should note that I changed the way I create the image file. Since I want to create a file that reflects an online file I simply download it instead of creating a Bitmap and then creating the file (this was done because at some point I needed the Bitmap but now I do it the other way around). The problems persist thought and are exactly the same:

I/ActivityManager(18852): Starting
activity: Intent {
act=android.intent.action.VIEW
dat=/sdcard/Android/data/com.myapp/files/image.jpg
typ=image/* flg=0x3800000
cmp=com.motorola.gallery/.ViewImage }
I/ActivityManager(18852): Start proc
com.motorola.gallery:ViewImage for
activity
com.motorola.gallery/.ViewImage:
pid=29187 uid=10017 gids={3003, 1015}
I/dalvikvm(29187): Debugger thread not
active, ignoring DDM send
(t=0x41504e4d l=38)
I/dalvikvm(29187): Debugger thread not
active, ignoring DDM send
(t=0x41504e4d l=64)
I/ActivityManager(18852): Process
com.handcent.nextsms (pid 29174) has died.
I/ViewImage(29187): In View Image
onCreate!
D/AndroidRuntime(29187): Shutting down VM
W/dalvikvm(29187): threadid=3: thread
exiting with uncaught exception
(group=0x4001b170)
E/AndroidRuntime(29187): Uncaught
handler: thread main exiting due to
uncaught exception
E/AndroidRuntime(29187):
java.lang.RuntimeException: Unable to
start activity
ComponentInfo{com.motorola.gallery/com.motorola.gallery.ViewImage}:
java.lang.NullPointerException
E/AndroidRuntime(29187): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
E/AndroidRuntime(29187): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
E/AndroidRuntime(29187): at
android.app.ActivityThread.access$2200(ActivityThread.java:119)
E/AndroidRuntime(29187): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
E/AndroidRuntime(29187): at
android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(29187): at
android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(29187): at
android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime(29187): at
java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime(29187): at
java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(29187): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime(29187): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime(29187): at
dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(29187): Caused by:
java.lang.NullPointerException
E/AndroidRuntime(29187): at
com.motorola.gallery.ImageManager.allImages(ImageManager.java:5621)
E/AndroidRuntime(29187): at
com.motorola.gallery.ImageManager.getSingleImageListByUri(ImageManager.java:5515)
E/AndroidRuntime(29187): at
com.motorola.gallery.ViewImage.onCreate(ViewImage.java:1801)
E/AndroidRuntime(29187): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime(29187): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
E/AndroidRuntime(29187): ... 11 more

View 3 Replies View Related

Android :: Opening Local HTML File Via Browser Intent

Aug 31, 2009

My open source application needs to browse local HTML files on the SD card, and WebView is not enough because I need history and bookmarks. I wrote the following code. It correctly opens the browser, but fails to reach catalog.html and in fact it just opens whatever page was last browsed:

Uri uri = Uri.parse("content://com.android.htmlfileprovider/sdcard/ myapp/catalog.html");
Intent intent = new Intent(); intent.setData(uri); intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity"); startActivity(intent);

View 2 Replies View Related

Android : Droid Email Intent Not Sending Attached File / Fix It?

Aug 29, 2010

I have created an app that sends an email with a recording, When the intent is fired and email is chosen as the app to send the attachment, you can see that there is an attachement but the attachment is not delivered. code...

View 1 Replies View Related

General :: SWF File Downloading Without Known Instruction

Apr 18, 2012

I noticed a file was downloaded to my Samsung Galaxy S2 whilst the phone wasn't in use with the screen off and locked. I've attached a screenshot of the download to show the file name.

The same file was downloaded again approximately ten minutes later, again without instruction.I then ran AVG which didn't identify anything (the Settings Security Issue is having USB Debugging switched on)..I recently restored my applications using Titanium Back Up after flashing a new ROM.

View 2 Replies View Related

Android :: Correct Intent Filter Configuration To Associate File Type?

Nov 10, 2010

This question has been asked [numerous times] before, but I have not seen any definitive answers, or examples of code that actually works. I would like to associate an Activity with a particular file type. For discussion, assume that I want my Activity to be associated with PDFs. Here is what I currently have. I have experimented with many different values and combinations of values in the intent-filter, but I have yet to get my Activity to start when a PDF is selected.

<activity name="com.mycompany.MyActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:mimeType="application/pdf" />
<data android:pathPattern="*.pdf" />
<data android:host="*" />
</intent-filter> </activity>

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved