Can anyone explain the File() parameters used to download file in android?
In Reference to this android file download problem
Can anyone explain what does this line mean in the code
FileOutputStream f = new FileOutputStream(new File(root,"Video.mp4"));
And what does it mean by the parameter root within the File()
.
Do I need to specify the root path
to save the file?
If it is the case then how do we specify the root path in android ?
Regards
Asked by: Kevin206 | Posted: 25-01-2022
Answer 1
And what does it mean by the parameter root within the File(). Do I need to specify the root path to save the file? if it is the case then how do we specify the root path in android?
The code snippet from the question you linked doesn't define the variable, but if the code is downloading a file to the device, I would assume that it's a path on the SD card. Environment.getExternalStorageDirectory()
will give you the root path to the SD card. You'll also need to specify the WRITE_EXTERNAL_STORAGE
permission in your manifest.
If you're working on the emulator, you can create a virtual SD card when you create the emulator image.
Answered by: Tara739 | Posted: 26-02-2022Answer 2
The java.io.File(File, String) or java.io.File(String, String) are standard java constructors for Java. The first argument is just the parent directory path, while the second is the actual file name. If the file is in the current working directory or you know the full path as one string you can avoid the 2 argument constructors.
Since you are trying to download a file you can just acquire the file through a normal URL.openStream() to get an InputStream to get the contents of your downloaded file. For writing the data out you will follow the example you linked to to write the contents.
I'm unsure what the root variable was pointed to in the example. I'm not able to help you beyond this though since I have only gone through the first Hello, Android example myself.
Answered by: Emily746 | Posted: 26-02-2022Similar questions
java - Using url with parameters to download image from internet for Android?
Using URL with parameters to download image from internet for Android???
This code is work,but I don't want that,I want to use a URL with parameters to download image.(ex:URL=http://yahoo.com/record?ProductID=1)
How to change this code?please.
bmp = this.GetNetBitmap("http://avatar.csdn.net/B/D...
android - camera preview parameters of Nexus one?
Any one please help me to solve my camera preview issue. am using a nexus one am setting the camera parameters to 640,480. but its showing force close error
my code is as follows
public class CameraPreview extends Activity {
private Preview mPreview;
public static ProgressDialog pdDetail;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceS...
android - How to start an Intent by passing some parameters to it?
I would like to pass some variables in the constructor of my ListActivity
I start activity via this code:
startActivity(new Intent (this, viewContacts.class));
I would like to use similar code, but to pass two strings to the constructor. How is possible?
Android: passing parameters between classes
I have a class2 which is involved by class1 when clicks are made. I have to pass some parameters/objects from class1 to class2. I only know the standard way which does not have an option of passing parameters.
// launch the full article
Intent i = new Intent(this, Class2.class);
startActivity(i);
android - Passing parameters to web service method in c#
I'm developing an android application .. which will send location data to a web service to store in the server database.
In Java:
I've used this protocol so the URI is: HTTP request instead of REST
HttpPost request = new HttpPost("http://trafficmapsa.com/GService.asmx/GPSdata?lon="+Lon+"&Lat="+Lat+"&speed="+speed);
In Asp.net (c#) web service will be:
[W...
java - How to add parameters to a HTTP GET request in Android?
I have a HTTP GET request that I am attempting to send. I tried adding the parameters to this request by first creating a BasicHttpParams object and adding the parameters to that object, then calling setParams( basicHttpParms ) on my HttpGet object. This method fails. But if I manually add my parameters to my URL (i.e. append ?param1=value1&param2=value2) it succeeds....
Starting an Android service with parameters
I want to start a service that has parameters
public BackgroundHelperService(String name)
How can I do this using
Intent service = new Intent(cnx, BackgroundHelperService.class);
I cannot pass the name param.
android - Setting relative layout parameters
So I'm trying to add an imageview to my current xml design - and its working decently. Now my main problem is that I cant seem to find a way to set the attributes for the image like where it needs to be displayed etc.
RelativeLayout mRelativeLayout = (RelativeLayout) findViewById(R.id.board);
ImageView i = new ImageView(this);
i.setImageResource(R.drawable.blue_1);
i.setAdjustViewBounds(true);
mRelativeLay...
android - Launching Google Maps with more parameters
I have read a lot of stuff about launching Google Maps in Android.
That's pretty easy:
Uri uri = Uri.parse("geo:38.899533,-77.036476");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
The problem is that the map is shown at a high zoom level and there is no marker on the map.
So, if the user move a little bit or something happen, the point is lost.
Is t...
android - how can I find the layout parameters of the toast widget?
I like the layout of the toast widget very much, that means rounded corners, transparency, light grey border. Is there any way to see the layout parameters of such android standard widgets like the toast?
I would like do define a TextView with the same layout parameters.
android - Static parameters not retained across Activities
I am developing an Android app and I am using a library I wrote. This library has a class that contains some static fields. One of them is a API key. This key is used by other classes in my library to make calls on a remote service.
I initialize the API key on my main Activity once when it is created and the savedInstanceState is null.
My problem lies in other activities as they sometimes use the correct AP...
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android