Downloading a website to a string - android

Having done some basic tutorials, I started making my first real android app in eclipse. I want this app to check if the text in an EditText matches the text on a website (this one: http://www.augustinianum.eu/roosterwijzigingen/14062012.pdf (it contains my school's schedule changes)). I've found out how to make the app check if the text in the EditText matches a string (with the method contains()), so now the only thing I need to do is to download all of the text of that website to a string. But I have no idea how to. Or is there maybe a method which I can check with if a website contains a certain word without downloading the website's text to a string.
Thank You!
(BTW I'm not English so plz forgive me if I've made some language-related mistakes.)
#androider I can't post my code in the comment box so here it is:
package me.moop.mytwitter;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;
import android.app.ProgressDialog;
public class MainActivity extends Activity {
Button mBtnCheck;
EditText mEtxtGroup;
ProgressDialog mProgressDialog;
TwitterUser mTwitterUser;
TextView mTxtv1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.nicelayout3);
mBtnCheck = (Button) findViewById(R.id.btnCheck);
mEtxtGroup = (EditText) findViewById(R.id.etxtGroup);
mTxtv1 = (TextView) findViewById(R.id.textView1);
}
public void checkScheduleChange(View view){
if (view == mBtnCheck){
String group;
group = mEtxtGroup.getText().toString();
if (group.length() > 0){
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage("Bezig met checken voor roosterwijzigingen...");
mProgressDialog.show();
try
{
URL url = new URL("http://www.augustinianum.eu/roosterwijzigingen/14062012.pdf");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null){
mProgressDialog.dismiss();
if(str.contains(mEtxtGroup.getText().toString())){
Toast.makeText(this, "U hebt een roosterwijziging.", Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(this, "U hebt geen roosterwijzigingen", Toast.LENGTH_LONG).show();
}
}
in.close();
} catch (MalformedURLException e) {
Toast.makeText(this, "Er is een fout opgetreden, probeer opniew.", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(this, "Er is een fout opgetreden, probeer opniew.", Toast.LENGTH_LONG).show();
}
}
else{
Toast.makeText(this, "Voer een klas in", Toast.LENGTH_LONG).show();
}
}
}
}
Here are the button's properties:
<Button
android:id="#+id/btnCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:clickable="true"
android:onClick="checkScheduleChange"
android:text="Check" >

You can get the text using InputStream Reader like this.
try
{
URL url = new URL("http://yourwebpage.com");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null)
{
// str is one line of text; readLine() strips the newline character(s)
// You can use the contain method here.
if(str.contains(editText.getText().toString))
{
You can perform your logic here!!!!!
}
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
Also add an additional permission in your apps Manifest file:
<uses-permission android:name="android.permission.INTERNET/>
//============================EDIT================================//
if (group.length() > 0)
{
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage("Bezig met checken voor roosterwijzigingen...");
mProgressDialog.show();
try
{
URL url = new URL("http://www.augustinianum.eu/roosterwijzigingen/14062012.pdf");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null){
if(str.contains(mEtxtGroup.getText().toString())){
if(mProgressDialog.isShowing())
{
mProgressDialog.dismiss();
}
Toast.makeText(this, "U hebt een roosterwijziging.", Toast.LENGTH_LONG).show();
break;
}
}
in.close();
} catch (MalformedURLException e) {
Toast.makeText(this, "Er is een fout opgetreden, probeer opniew.", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(this, "Er is een fout opgetreden, probeer opniew.", Toast.LENGTH_LONG).show();
}
if(mProgressDialog.isShowing())
{
mProgressDialog.dismiss();
}
}
else{
Toast.makeText(this, "Voer een klas in", Toast.LENGTH_LONG).show();
}

This is a good related Java question: How do you Programmatically Download a Webpage in Java
You can then implement whatever method you choose into your app. One thing to note is that you will need to enable the INTERNET permission on your app in order to access the internet.

Related

android textfile from sd card reading error [duplicate]

I am new to Android development.
I need to read a text file from the SD card and display that text file.
Is there any way to view a text file directly in Android or else how can I read and display the contents of a text file?
In your layout you'll need something to display the text. A TextView is the obvious choice. So you'll have something like this:
<TextView
android:id="#+id/text_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
And your code will look like this:
//Find the directory for the SD Card using the API
//*Don't* hardcode "/sdcard"
File sdcard = Environment.getExternalStorageDirectory();
//Get the text file
File file = new File(sdcard,"file.txt");
//Read text from file
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
br.close();
}
catch (IOException e) {
//You'll need to add proper error handling here
}
//Find the view by its id
TextView tv = (TextView)findViewById(R.id.text_view);
//Set the text
tv.setText(text);
This could go in the onCreate() method of your Activity, or somewhere else depending on just what it is you want to do.
In response to
Don't hardcode /sdcard/
Sometimes we HAVE TO hardcode it as in some phone models the API method returns the internal phone memory.
Known types: HTC One X and Samsung S3.
Environment.getExternalStorageDirectory().getAbsolutePath() gives a different path - Android
You should have READ_EXTERNAL_STORAGE permission for reading sdcard.
Add permission in manifest.xml
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
From android 6.0 or higher, your app must ask user to grant the dangerous permissions at runtime. Please refer this link
Permissions overview
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 0);
}
}
package com.example.readfilefromexternalresource;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import android.os.Build;
public class MainActivity extends Activity {
private TextView textView;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView = (TextView)findViewById(R.id.textView);
String state = Environment.getExternalStorageState();
if (!(state.equals(Environment.MEDIA_MOUNTED))) {
Toast.makeText(this, "There is no any sd card", Toast.LENGTH_LONG).show();
} else {
BufferedReader reader = null;
try {
Toast.makeText(this, "Sd card available", Toast.LENGTH_LONG).show();
File file = Environment.getExternalStorageDirectory();
File textFile = new File(file.getAbsolutePath()+File.separator + "chapter.xml");
reader = new BufferedReader(new FileReader(textFile));
StringBuilder textBuilder = new StringBuilder();
String line;
while((line = reader.readLine()) != null) {
textBuilder.append(line);
textBuilder.append("\n");
}
textView.setText(textBuilder);
} catch (FileNotFoundException e) {
// TODO: handle exception
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
if(reader != null){
try {
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
}
BufferedReader br = null;
try {
String fpath = Environment.getExternalStorageDirectory() + <your file name>;
try {
br = new BufferedReader(new FileReader(fpath));
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
String line = "";
while ((line = br.readLine()) != null) {
//Do something here
}
Beware: some phones have 2 sdcards , an internal fixed one and a removable card.
You can find the name of the last one via a standard app:"Mijn Bestanden" ( in English: "MyFiles" ? )
When I open this app (item:all files) the path of the open folder is "/sdcard" ,scrolling down there is an entry "external-sd" , clicking this opens the folder "/sdcard/external_sd/" .
Suppose I want to open a text-file "MyBooks.txt" I would use something as :
String Filename = "/mnt/sdcard/external_sd/MyBooks.txt" ;
File file = new File(fname);...etc...

openFileInput reading only 1 line

I am accessing a file from my fragment in my Android app.
But my problem is that only 1 line of that file is being read.
My code is:
FragmentTab2.java
package com.adhish.pagertabstriptutorial;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class FragmentTab2 extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Get the view from fragmenttab2.xml
View v = inflater.inflate(R.layout.fragmenttab2, container, false);
TextView txt = (TextView)v.findViewById(R.id.optext);
try
{
FileInputStream fIn = getActivity().openFileInput("sample_details.txt");
InputStreamReader in = new InputStreamReader(fIn);
BufferedReader bufferedReader = new BufferedReader(in);
//StringBuilder sb = new StringBuilder();
String line = null;
String str = "";
while ((line = bufferedReader.readLine()) != null) {
str += line;
}
txt.setText(str);
bufferedReader.close();
in.close();
}
catch (Exception e)
{
Log.e("File not found.",e.toString());
}
return v;
}
}
The code which writes the file (in a different fragment) is:
#Override
public void onClick(View view)
{
if(view == getView().findViewById(R.id.button1))
{
//Call all the elements of this Fragment here becuase they are accessible easily through
//getView(); method. Use the getText(); method to get the Text and toString(); to convert
//it.
String name = ((EditText)getView().findViewById(R.id.name)).getText().toString();
String email = ((EditText)getView().findViewById(R.id.email)).getText().toString();
if(name.isEmpty() || email.isEmpty())
{
Toast.makeText(getActivity(), "Cannot store empty values !", Toast.LENGTH_SHORT).show();
}
else
{
try
{
FileOutputStream fOut = getActivity().openFileOutput("sample_details.txt", Context.MODE_MULTI_PROCESS);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fOut);
outputStreamWriter.write(name + " " + email + ";");
Log.e("String Concat Done", "Concatenation of the Strings is done to write in the File. Write Success.");
outputStreamWriter.flush();
Log.e("Flush","Flush Success");
outputStreamWriter.close();
fOut.close();
Log.e("Stream Closed","Both Streams are flushed and closed");
Toast.makeText(getActivity(), "Submitted", Toast.LENGTH_SHORT).show();
}
catch (Exception e)
{
Toast.makeText(getActivity(), "FAILED !", Toast.LENGTH_SHORT).show();
Log.e("Error in File Write",e.toString());
}
}
}
}
I don't know the correct way of implementing this.
Please let me know in detail how to do it, because I am new to Android.
Thanks.
Because your
FileOutputStream fOut = getActivity().openFileOutput("sample_details.txt", Context.MODE_MULTI_PROCESS);
should be
openFileOutput(yourFile, Context.MODE_APPEND);
FileOutputStream also have a constructor where you can append to the original file if you don't have context to be used with Android's openFileOutput() instead.
Extra reference for similar questions: OutputStreamWriter does not append

Proper use of openFileInput

I am new to Android Development, and I want to create an App which stores data in a file, and then reads the Data from the file. For that I have created 2 Tabs. Tab1 shows the form to enter data. And Tab2 shows the saved data.
FragmentTab1.java
package com.adhish.pagertabstriptutorial;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Toast;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
public class FragmentTab1 extends Fragment implements View.OnClickListener {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Get the view from fragmenttab1.xml
//first inflate the view.
View v = inflater.inflate(R.layout.fragmenttab1, container, false);
//then access the elements
v.findViewById(R.id.button1).setOnClickListener(this);
//then return the view
return v;
}
#Override
public void onClick(View view)
{
if(view == getView().findViewById(R.id.button1))
{
//Call all the elements of this Fragment here becuase they are accessible easily through
//getView(); method. Use the getText(); method to get the Text and toString(); to convert
//it.
String name = ((EditText)getView().findViewById(R.id.name)).getText().toString();
String email = ((EditText)getView().findViewById(R.id.email)).getText().toString();
if(name.isEmpty() || email.isEmpty())
{
Toast.makeText(getActivity(), "Cannot store empty values !", Toast.LENGTH_SHORT).show();
}
else
{
try
{
FileOutputStream fOut = getActivity().openFileOutput("sample_details.txt", Context.MODE_MULTI_PROCESS);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fOut);
outputStreamWriter.write(name + " " + email + ";");
Log.e("String Concat Done", "Concatenation of the Strings is done to write in the File. Write Success.");
outputStreamWriter.flush();
Log.e("Flush","Flush Success");
outputStreamWriter.close();
fOut.close();
Log.e("Stream Closed","Both Streams are flushed and closed");
Toast.makeText(getActivity(), "Submitted", Toast.LENGTH_SHORT).show();
}
catch (Exception e)
{
Toast.makeText(getActivity(), "FAILED !", Toast.LENGTH_SHORT).show();
Log.e("Error in File Write",e.toString());
}
}
}
}
}
FragmentTab2.java
package com.adhish.pagertabstriptutorial;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class FragmentTab2 extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Get the view from fragmenttab2.xml
View v = inflater.inflate(R.layout.fragmenttab2, container, false);
TextView txt = (TextView)v.findViewById(R.id.optext);
try
{
FileInputStream fIn = getActivity().openFileInput("sample_details.txt");
InputStreamReader in = new InputStreamReader(fIn);
BufferedReader bufferedReader = new BufferedReader(in);
StringBuilder sb = new StringBuilder();
String line = null;
String str = null;
while ((line = bufferedReader.readLine()) != null) {
sb.append(line).append("\n");
}
txt.setText(line);
bufferedReader.close();
in.close();
}
catch (Exception e)
{
Log.e("File not found.",e.toString());
}
return v;
}
}
Only one line is displayed in the text view.
Please help me in detail as I am very new to Android.
Please suggest a better way in detail if exists.
I am attaching my UI here:
Thanks.
First Edit your try block with this code
FileOutputStream fOut = openFileOutput(
"sample_details.txt", Context.MODE_MULTI_PROCESS);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fOut);
JSONObject jobj=new JSONObject();
jobj.put("Name", "name");
jobj.put("Email", "email");
outputStreamWriter.write(jobj.toString());
Log.e("String Concat Done",
"Concatenation of the Strings is done to write in the File. Write Success.");
outputStreamWriter.flush();
Log.e("Flush", "Flush Success");
outputStreamWriter.close();
fOut.close();
Log.e("Stream Closed", "Both Streams are flushed and closed");
And in second tab(fragment) first get(read) the string as:
public static String convertStreamToString(InputStream is) throws Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
reader.close();
return sb.toString();
}
public static String getStringFromFile (String filePath) throws Exception {
File fl = new File(filePath);
FileInputStream fin = new FileInputStream(fl);
String ret = convertStreamToString(fin);
//Make sure you close all streams.
fin.close();
return ret;
}
You will get(read) the string by calling getStringFromFile(filepath) method
the string is in JSON form so you have to parse it as:
public void Readvalue(String jsonvalue)
{
try {
JSONObject jobj=new JSONObject(jsonvalue);
String name=jobj.getString("Name");
String email=jobj.getString("Email");
System.out.println("Name is : "+name +" Email is : "+email);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

how do i load remote text from a text file into android textview?

I have gone through all the examples and I can not seem to get this to work.
This is my current code:
package hello.android;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroidActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView) findViewById(R.id.textView1);
try {
// Create a URL for the desired page
URL url = new URL("http://xlradioaustin.com/song/CurrentSong.txt");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
// str is one line of text; readLine() strips the newline character(s)
}
in.close();
tv.setText(str);
} catch (MalformedURLException e) {
tv.setText("mal");
} catch (IOException e) {
tv.setText("io");
}
}
}
Assuming your Android device is online and you've granted your app the INTERNET permission, try this:
try {
// Create a URL for the desired page
URL url = new URL("http://xlradioaustin.com/song/CurrentSong.txt");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
StringBuilder sb = new StringBuilder(100);
while ((str = in.readLine()) != null) {
sb.append(str);
// str is one line of text; readLine() strips the newline character(s)
}
in.close();
tv.setText(sb.toString());
} catch (MalformedURLException e) {
tv.setText("mal");
} catch (IOException e) {
tv.setText("io");
}
Let me know if that works: you are currently looping until str is null, then using that null value.
A follow up on the answer, it worked after adding
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}

How can I read a text file from the SD card in Android?

I am new to Android development.
I need to read a text file from the SD card and display that text file.
Is there any way to view a text file directly in Android or else how can I read and display the contents of a text file?
In your layout you'll need something to display the text. A TextView is the obvious choice. So you'll have something like this:
<TextView
android:id="#+id/text_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
And your code will look like this:
//Find the directory for the SD Card using the API
//*Don't* hardcode "/sdcard"
File sdcard = Environment.getExternalStorageDirectory();
//Get the text file
File file = new File(sdcard,"file.txt");
//Read text from file
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
br.close();
}
catch (IOException e) {
//You'll need to add proper error handling here
}
//Find the view by its id
TextView tv = (TextView)findViewById(R.id.text_view);
//Set the text
tv.setText(text);
This could go in the onCreate() method of your Activity, or somewhere else depending on just what it is you want to do.
In response to
Don't hardcode /sdcard/
Sometimes we HAVE TO hardcode it as in some phone models the API method returns the internal phone memory.
Known types: HTC One X and Samsung S3.
Environment.getExternalStorageDirectory().getAbsolutePath() gives a different path - Android
You should have READ_EXTERNAL_STORAGE permission for reading sdcard.
Add permission in manifest.xml
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
From android 6.0 or higher, your app must ask user to grant the dangerous permissions at runtime. Please refer this link
Permissions overview
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 0);
}
}
package com.example.readfilefromexternalresource;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import android.os.Build;
public class MainActivity extends Activity {
private TextView textView;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView = (TextView)findViewById(R.id.textView);
String state = Environment.getExternalStorageState();
if (!(state.equals(Environment.MEDIA_MOUNTED))) {
Toast.makeText(this, "There is no any sd card", Toast.LENGTH_LONG).show();
} else {
BufferedReader reader = null;
try {
Toast.makeText(this, "Sd card available", Toast.LENGTH_LONG).show();
File file = Environment.getExternalStorageDirectory();
File textFile = new File(file.getAbsolutePath()+File.separator + "chapter.xml");
reader = new BufferedReader(new FileReader(textFile));
StringBuilder textBuilder = new StringBuilder();
String line;
while((line = reader.readLine()) != null) {
textBuilder.append(line);
textBuilder.append("\n");
}
textView.setText(textBuilder);
} catch (FileNotFoundException e) {
// TODO: handle exception
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
if(reader != null){
try {
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
}
BufferedReader br = null;
try {
String fpath = Environment.getExternalStorageDirectory() + <your file name>;
try {
br = new BufferedReader(new FileReader(fpath));
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
String line = "";
while ((line = br.readLine()) != null) {
//Do something here
}
Beware: some phones have 2 sdcards , an internal fixed one and a removable card.
You can find the name of the last one via a standard app:"Mijn Bestanden" ( in English: "MyFiles" ? )
When I open this app (item:all files) the path of the open folder is "/sdcard" ,scrolling down there is an entry "external-sd" , clicking this opens the folder "/sdcard/external_sd/" .
Suppose I want to open a text-file "MyBooks.txt" I would use something as :
String Filename = "/mnt/sdcard/external_sd/MyBooks.txt" ;
File file = new File(fname);...etc...

Categories

Resources