Reading Arabic from UTF-8 encoded Text file in android? - android

I am working on an application in which I have a some text in English and Arabic. For the sake of example I can say it as a words meaning application. The word is in English and user will get it's meaning in Arabic.
For Example:
Test اختبار // Test is the word and then there is it's meaning in Arabic
But when I read this local file I don't get Arabic as intended. Instead I get some strange characters. I am making sure that file is UTF-8 encoded and when I read the file I again pass encoding scheme to be UTF-8..but it does not wwork. Code snippet is as follows:
InputStream inputStream = resources.openRawResource(R.raw.textfile);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"));
try {
String line;
while((line = reader.readLine()) != null) {
String[] strings = TextUtils.split(line, " ");
if (strings.length < 2) continue;
addWord(strings[0].trim(), strings[1].trim());
}
} finally {
reader.close();
}
Any help is appreciated..Thanks..!!!

I actually built an helper class that handles FileIO (and is completely compatible with Hebrew) so I guess Arabic will be no problem:
/***
*
* #author Android Joker ©
* Do NOT copy without confirmation!
* Thanks!
*
*/
public class FileMethods {
private Boolean isOk;
private Context mContext;
private String fileName;
public FileMethods(Context c, String FILENAME) {
this.isOk = true;
this.mContext = c;
this.fileName = FILENAME;
}
public void reWrite(Object DATA) {
//For deleting the content of the file and then writing
try {
FileOutputStream fos = mContext.openFileOutput(this.fileName, Context.MODE_PRIVATE);
fos.write(DATA.toString().getBytes());
fos.close();
Log.i("File Writing ("+this.fileName+")", "Success!");
isOk = true;
}
catch (IOException e) {
e.printStackTrace();
Log.e("File Writing ("+this.fileName+")", "Failed!");
isOk = false;
}
}
public void Write(Object DATA) {
//For keeping the previous contents and continue writing
String data = Read("") + DATA.toString() + "\n";
try {
FileOutputStream fos = mContext.openFileOutput(this.fileName, Context.MODE_PRIVATE);
fos.write(data.getBytes());
fos.close();
Log.i("File Writing ("+this.fileName+")", "Success!");
isOk = true;
}
catch (IOException e) {
e.printStackTrace();
Log.e("File Writing ("+this.fileName+")", "Failed!");
isOk = false;
}
}
public void Clear() {
//For deleting all the file contents
try {
FileOutputStream fos = mContext.openFileOutput(this.fileName, Context.MODE_PRIVATE);
fos.write("".getBytes());
fos.close();
Log.i("Cleared"+"("+this.fileName+")", "Success!");
isOk = true;
}
catch (IOException e) {
e.printStackTrace();
Log.e("Cleared"+"("+this.fileName+")", "Failed!");
isOk = false;
}
}
public String Read(String inCaseOfFailure) {
//For reading (If reading failed for any reason, inCaseOfFailure will be written)
String info = "";
try {
FileInputStream fis = mContext.openFileInput(this.fileName);
byte[] dataArray = new byte[fis.available()];
if (dataArray.length>0) {
while(fis.read(dataArray)!=-1)
{
info = new String(dataArray);
}
fis.close();
Log.i("File Reading ("+this.fileName+")","Success!");
isOk = true;
}
else {
try {
FileOutputStream fos = mContext.openFileOutput(this.fileName, Context.MODE_PRIVATE);
fos.write(inCaseOfFailure.getBytes());
fos.close();
Log.e("File Writing In Case Of Failure ("+this.fileName+")", "Success!");
isOk = true;
}
catch (Exception e) {
e.printStackTrace();
isOk = false;
Log.e("File Writing In Case Of Failure ("+this.fileName+")", "Failed!");
Log.e("File Writing In Case Of Failure ("+this.fileName+")", "MOVING ON");
}
}
}
catch (FileNotFoundException e) {
try {
FileOutputStream fos = mContext.openFileOutput(this.fileName, Context.MODE_PRIVATE);
if (inCaseOfFailure != null) {
fos.write(inCaseOfFailure.getBytes());
fos.close();
Log.e("File Writing In Case Of Failure ("+this.fileName+")", "Success!");
isOk = true;
}
else {
Log.e("File Writing In Case Of Failure ("+this.fileName+")", "Failed!");
isOk = false;
}
}
catch (IOException e1) {
e.printStackTrace();
Log.e("File Writing In Case Of Failure ("+this.fileName+")", "Failed!");
isOk = false;
}
}
catch (IOException e) {
e.printStackTrace();
Log.e("File Reading ("+this.fileName+")", "Failed!");
isOk = false;
}
return info;
}
public Boolean GetIsOK() {
//Method that checks whether the FileIO was successfully running or not
Boolean temp = isOk;
isOk = true;
return temp;
}
}
Each instance of the class handles another file (FILENAME).
Hope this helps!

Related

com.googlecode.mp4parser fails for mp3 audio file?

I am using the com.googlecode.mp4parser library to merge audio files. I have an external audio mp3 file which I store in raw resources. This file fails to merge due to following exception, Below is my code :
Reading a file from raw folder :
InputStream is = context.getResources().openRawResource(R.raw.my_mp3_file);
OutputStream output = null;
try {
File file = new File(context.getFilesDir(), "silence.mp3");
if(!file.exists()) {
file.createNewFile();
}
output = new FileOutputStream(file);
byte[] buffer = new byte[4 * 1024]; // or other buffer size
int read;
while ((read = is.read(buffer)) != -1) {
output.write(buffer, 0, read);
}
output.flush();
output.close();
fileReference= file;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace(); // handle exception, define IOException and others
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Code that reads movie ( Which is failing ) :
if(fileReference.exists()) {
Movie m = new MovieCreator().build(fileReference.getAbsolutePath());
}
While getting this Movie m my code fails throwing the exception :
java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.coremedia.iso.boxes.MovieBox.getBoxes(java.lang.Class)' on a null object reference
It works for some mp3 files fails for raw resource files ? What's wrong here ?
Here are my conclusion and solution after a lot of research
MP4Parser for merging audio and video only use .m4a extension
String root = Environment.getExternalStorageDirectory().toString();
String audio = root + "/" + "tests.m4a";
String video = root + "/" + "output.mp4";
String output = root + "/" + "aud_vid.mp4";
mux(video, audio, output);
and here is the method
public boolean mux(String videoFile, String audioFile, String outputFile) {
Movie video;
try {
video = new MovieCreator().build(videoFile);
} catch (RuntimeException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
Movie audio;
try {
audio = new MovieCreator().build(audioFile);
} catch (IOException e) {
e.printStackTrace();
return false;
} catch (NullPointerException e) {
e.printStackTrace();
return false;
}
Track audioTrack = audio.getTracks().get(0);
video.addTrack(audioTrack);
Container out = new DefaultMp4Builder().build(video);
FileOutputStream fos;
try {
fos = new FileOutputStream(outputFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
}
BufferedWritableFileByteChannel byteBufferByteChannel = new BufferedWritableFileByteChannel(fos);
try {
out.writeContainer(byteBufferByteChannel);
byteBufferByteChannel.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
private static class BufferedWritableFileByteChannel implements WritableByteChannel {
private static final int BUFFER_CAPACITY = 1000000;
private boolean isOpen = true;
private final OutputStream outputStream;
private final ByteBuffer byteBuffer;
private final byte[] rawBuffer = new byte[BUFFER_CAPACITY];
private BufferedWritableFileByteChannel(OutputStream outputStream) {
this.outputStream = outputStream;
this.byteBuffer = ByteBuffer.wrap(rawBuffer);
}
#Override
public int write(ByteBuffer inputBuffer) throws IOException {
int inputBytes = inputBuffer.remaining();
if (inputBytes > byteBuffer.remaining()) {
dumpToFile();
byteBuffer.clear();
if (inputBytes > byteBuffer.remaining()) {
throw new BufferOverflowException();
}
}
byteBuffer.put(inputBuffer);
return inputBytes;
}
#Override
public boolean isOpen() {
return isOpen;
}
#Override
public void close() throws IOException {
dumpToFile();
isOpen = false;
}
private void dumpToFile() {
try {
outputStream.write(rawBuffer, 0, byteBuffer.position());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Seem like this issue happens because Google devs have forgotten to handle that NullPointerException case. After several hours diving into the code base, I finally found the solution and It works very fine, you can try this:
Movie movie;
try{
movie = MovieCreator.build(videoPath);
}catch(NullPointerException e){
Log.d("AsyncTask", "Catch null getMovieBoxes");
FileDataSourceImpl fileDataSource = new FileDataSourceImpl(new File(videoPath));
IsoFile isoFile = new IsoFile(fileDataSource);
List<TrackBox> trackBoxes = isoFile.getBoxes(TrackBox.class);
for (TrackBox trackBox : trackBoxes) {
SchemeTypeBox schm = Path.getPath(trackBox, "mdia[0]/minf[0]/stbl[0]/stsd[0]/enc.[0]/sinf[0]/schm[0]");
if (schm != null && (schm.getSchemeType().equals("cenc") || schm.getSchemeType().equals("cbc1"))) {
movie.addTrack(new CencMp4TrackImplImpl(fileDataSource.toString() + "[" + trackBox.getTrackHeaderBox().getTrackId() + "]", trackBox));
} else {
movie.addTrack(new Mp4TrackImpl(fileDataSource.toString() + "[" + trackBox.getTrackHeaderBox().getTrackId() + "]" , trackBox));
}
}
}

android replace string by another string in file on sdcard

I've created Test.txt on sdcard and write string "test example" on it.
after that, I replace string "test" by "etc" in Test.txt.
this is my code :
String origin_str, old_str , new_str;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_t2);
origin_str = "test example";
old_str = "test";
new_str = "etc";
Button bt_create2 = (Button)findViewById(R.id.bt_createfileT2);
bt_create2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
File newFolder = new File(Environment.getExternalStorageDirectory(), "TestFolder");
if (!newFolder.exists()) {
newFolder.mkdir();
}
File file = new File(newFolder, "Test" + ".txt");
if (!file.exists()) {
file.createNewFile();
FileOutputStream fOut = new FileOutputStream(file);
OutputStreamWriter myOutWriter =new OutputStreamWriter(fOut);
myOutWriter.append(origin_str);
myOutWriter.close();
fOut.close();
}
} catch (Exception e) {
System.out.println("e: " + e);
}
}
});
Button bt_replacefileT2 = (Button)findViewById(R.id.bt_replacefileT2);
bt_replacefileT2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
File file = new File(Environment.getExternalStorageDirectory() + "/TestFolder/Test.txt");
FileInputStream in = new FileInputStream(file);
int len = 0;
byte[] data1 = new byte[1024];
while ( -1 != (len = in.read(data1)) ){
if(new String(data1, 0, len).contains(old_str)){
String s = "";
s = s.replace(old_str, new_str);
}
}
}
catch (Exception e){
e.printStackTrace();
}
}
});
with this code, it was create Test.txt on sdcard and write "test example" on it.
but when replace string "test" by "etc", it not working.
how to fix it?
I will give my code, always worked for me :)
Hope thi can help you :DD
public void saveString(String text){
if(this.isExternalStorageAvailable()){
if(!this.isExternalStorageReadOnly()){
try {
FileOutputStream fos = new FileOutputStream(
new File(this.getExternalFilesDir("text"), "text.dat"));
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeBytes(text);
oos.close();
fos.close();
} catch (FileNotFoundException e) {
//Toast.makeText(main, "Eror opening file", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
//Toast.makeText(main, "Eror saving String", Toast.LENGTH_SHORT).show();
}
}
}
}
private static boolean isExternalStorageAvailable(){
String estadoSD = Environment.getExternalStorageState();
if(Environment.MEDIA_MOUNTED.equals(estadoSD))
return true;
return false;
}
private static boolean isExternalStorageReadOnly(){
String estadoSD = Environment.getExternalStorageState();
if(Environment.MEDIA_MOUNTED_READ_ONLY.equals(estadoSD))
return true;
return false;
}
public String getString(){
FileInputStream fis = null;
ObjectInputStream ois = null;
if(this.isExternalStorageAvailable()) {
try {
fis = new FileInputStream(
new File(this.getExternalFilesDir("text"), "text.dat"));
ois = new ObjectInputStream(fis);
String text = (String)ois.readObject();
return familia;
} catch (FileNotFoundException e) {
//Toast.makeText(main, "The file text doesnt exist", Toast.LENGTH_SHORT).show();
} catch (StreamCorruptedException e) {
//Toast.makeText(main, "Eror opening file", Toast.LENGTH_SHORT).show();
} catch(EOFException e){
try {
if(ois != null)
ois.close();
if(fis != null)
fis.close();
} catch (IOException e1) {
e1.printStackTrace();
}
} catch (IOException e) {
//Toast.makeText(main, "eror reading file", Toast.LENGTH_SHORT).show();
} catch (ClassNotFoundException e) {
//Toast.makeText(main, "String class doesnt exist", Toast.LENGTH_SHORT).show();
}
}
return null;
}
try this
File file = new File(Environment.getExternalStorageDirectory() + "/TestFolder/Test.txt");
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
line = line.replace(old,new);
}
br.close();
FileOutputStream fOut = new FileOutputStream(file);
OutputStreamWriter myOutWriter =new OutputStreamWriter(fOut);
myOutWriter.write(line);
myOutWriter.close();
fOut.close();
}
catch (IOException e) {
//You'll need to add proper error handling here
}

Android where file is saved FileOutputStream

Here how I write bytes to a file. I'm using FileOutputStream
private final Handler handler = new Handler(){
#Override
public void handleMessage(Message msg) {
FragmentActivity activity = getActivity();
byte[] readBuffer = (byte[]) msg.obj;
FileOutputStream out = null;
try {
out = new FileOutputStream("myFile.xml");
out.write(readBuffer);
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
and now I want to open that file, so I need to have path of that file. So how I need to open that file?
EDIT:
Here how I read from file, but I can't see anything...
BufferedReader reader = null;
FileInputStream s = null;
try {
s = new FileInputStream("mano.xml");
reader = new BufferedReader(new InputStreamReader(s));
String line = reader.readLine();
Log.d(getTag(), line);
while (line != null) {
Log.d(getTag(), line);
line = reader.readLine();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
I recommend to use this for writting:
OutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath()+"/yourfilename");
So to read the location:
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+transaction.getUniqueId()+".pdf");
To read the path:
file.getAbsolutePath();
Your file is save in path /Data/Data/Your package Name/files/myFile.xml
you can use this.getFileDir() method to get the path of the files folder on the Application.
So use this.getFileDir() + "myFile.xml" to read the file.
How it is reported inside the developers guide you have to specify where you want to save your file. You can choose between:
Saving the file in the internal storage:
String filename = "myfile";
String string = "Hello world!";
FileOutputStream outputStream;
try {
outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
outputStream.write(string.getBytes());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
Or on second instance you could save your file in external storage:
// Checks if external storage is available to at least read
public boolean isExternalStorageReadable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
return true;
}
return false;
}
Just remember to set permissions!!!!
Here there is the entire documentation: Documentation

Install vCard using android app?

Is there any way to install a vCard using android app, as soon as it starts for the first time.
Although for running any block of code for the first time, I can use these lines ...
if (isFirstTime()) {
//First time code
}
and
private boolean isFirstTime()
{
SharedPreferences preferences = getPreferences(MODE_PRIVATE);
boolean ranBefore = preferences.getBoolean("RanBefore", false);
if (!ranBefore) {
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("RanBefore", true);
editor.commit();
}
return ranBefore;
}
but how will I be able to install a vCard from app.
Note: Although I have the vCard already made, and can be put in the raw directory.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(storage_path+vfile)),"text/x-vcard");
startActivity(intent);
Edit
Copy vcard to sdcard
private void copyAssets() { AssetManager assetManager = getAssets();
String[] files = null;
try { files = assetManager.list(""); } catch (IOException e)
{ Log.e("tag", "Failed to get asset file list.", e);
} for(String filename : files)
{
InputStream in = null; OutputStream out = null;
try { in = assetManager.open(filename);
File outFile = new File(getExternalFilesDir(null), filename);
out = new FileOutputStream(outFile); copyFile(in, out); } catch(IOException e) {
Log.e("tag", "Failed to copy asset file: " + filename, e); }
finally {
if (in != null) { try { in.close();
} catch (IOException e) { // NOOP }
} if (out != null) {
try { out.close(); } catch (IOException e) { // NOOP }
}
}
}
} private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024]; int read; while((read = in.read(buffer)) != -1){ out.write(buffer, 0, read);
} }
Then type the location where I have written storage_path

Error For Below code

Getting Error for the below package:
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Cell;
can any help me for the below code to resolve the error.
public class AndroidReadExcelActivity extends Activity implements OnClickListener{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View writeButton = findViewById(R.id.write);
writeButton.setOnClickListener(this);
View readButton = findViewById(R.id.read);
readButton.setOnClickListener(this);
View writeExcelButton = findViewById(R.id.writeExcel);
writeExcelButton.setOnClickListener(this);
View readExcelButton = findViewById(R.id.readExcel);
readExcelButton.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.write:
saveFile(this,"myFile.txt");
break;
case R.id.read:
readFile(this,"myFile.txt");
break;
case R.id.writeExcel:
saveExcelFile(this,"myExcel.xls");
break;
case R.id.readExcel:
readExcelFile(this,"myExcel.xls");
break;
}
}
private static boolean saveFile(Context context, String fileName) {
// check if available and not read only
if (!isExternalStorageAvailable() || isExternalStorageReadOnly()) {
Log.w("FileUtils", "Storage not available or read only");
return false;
}
// Create a path where we will place our List of objects on external storage
File file = new File(context.getExternalFilesDir(null), fileName);
PrintStream p = null; // declare a print stream object
boolean success = false;
try {
OutputStream os = new FileOutputStream(file);
// Connect print stream to the output stream
p = new PrintStream(os);
p.println("This is a TEST");
Log.w("FileUtils", "Writing file" + file);
success = true;
} catch (IOException e) {
Log.w("FileUtils", "Error writing " + file, e);
} catch (Exception e) {
Log.w("FileUtils", "Failed to save file", e);
} finally {
try {
if (null != p)
p.close();
} catch (Exception ex) {
}
}
return success;
}
private static void readFile(Context context, String filename) {
if (!isExternalStorageAvailable() || isExternalStorageReadOnly())
{
Log.w("FileUtils", "Storage not available or read only");
return;
}
FileInputStream fis = null;
try
{
File file = new File(context.getExternalFilesDir(null), filename);
fis = new FileInputStream(file);
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fis);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
Log.w("FileUtils", "File data: " + strLine);
Toast.makeText(context, "File Data: " + strLine , Toast.LENGTH_SHORT).show();
}
in.close();
}
catch (Exception ex) {
Log.e("FileUtils", "failed to load file", ex);
}
finally {
try {if (null != fis) fis.close();} catch (IOException ex) {}
}
return;
}
private static boolean saveExcelFile(Context context, String fileName) {
// check if available and not read only
if (!isExternalStorageAvailable() || isExternalStorageReadOnly()) {
Log.w("FileUtils", "Storage not available or read only");
return false;
}
boolean success = false;
//New Workbook
Workbook wb = new HSSFWorkbook();
Cell c = null;
//Cell style for header row
CellStyle cs = wb.createCellStyle();
cs.setFillForegroundColor(HSSFColor.LIME.index);
cs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
//New Sheet
Sheet sheet1 = null;
sheet1 = wb.createSheet("myOrder");
// Generate column headings
Row row = sheet1.createRow(0);
c = row.createCell(0);
c.setCellValue("Item Number");
c.setCellStyle(cs);
c = row.createCell(1);
c.setCellValue("Quantity");
c.setCellStyle(cs);
c = row.createCell(2);
c.setCellValue("Price");
c.setCellStyle(cs);
sheet1.setColumnWidth(0, (15 * 500));
sheet1.setColumnWidth(1, (15 * 500));
sheet1.setColumnWidth(2, (15 * 500));
// Create a path where we will place our List of objects on external storage
File file = new File(context.getExternalFilesDir(null), fileName);
FileOutputStream os = null;
try {
os = new FileOutputStream(file);
wb.write(os);
Log.w("FileUtils", "Writing file" + file);
success = true;
} catch (IOException e) {
Log.w("FileUtils", "Error writing " + file, e);
} catch (Exception e) {
Log.w("FileUtils", "Failed to save file", e);
} finally {
try {
if (null != os)
os.close();
} catch (Exception ex) {
}
}
return success;
}
private static void readExcelFile(Context context, String filename) {
if (!isExternalStorageAvailable() || isExternalStorageReadOnly())
{
Log.w("FileUtils", "Storage not available or read only");
return;
}
try{
// Creating Input Stream
File file = new File(context.getExternalFilesDir(null), filename);
FileInputStream myInput = new FileInputStream(file);
// Create a POIFSFileSystem object
POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);
// Create a workbook using the File System
HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);
// Get the first sheet from workbook
HSSFSheet mySheet = myWorkBook.getSheetAt(0);
/** We now need something to iterate through the cells.**/
Iterator<Row> rowIter = mySheet.rowIterator();
while(rowIter.hasNext()){
HSSFRow myRow = (HSSFRow) rowIter.next();
Iterator<Cell> cellIter = myRow.cellIterator();
while(cellIter.hasNext()){
HSSFCell myCell = (HSSFCell) cellIter.next();
Log.w("FileUtils", "Cell Value: " + myCell.toString());
Toast.makeText(context, "cell Value: " + myCell.toString(), Toast.LENGTH_SHORT).show();
}
}
}catch (Exception e){e.printStackTrace(); }
return;
}
public static boolean isExternalStorageReadOnly() {
String extStorageState = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(extStorageState)) {
return true;
}
return false;
}
public static boolean isExternalStorageAvailable() {
String extStorageState = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(extStorageState)) {
return true;
}
return false;
}
}
You need to Import Apache POI library
Tutorial using this library can be found here
Go through the official website for latest library release and go through this answer as well.
Jar Download URL click on any mirror link under HTTP.
public class AndroidReadExcelActivity
reemplaced for name your archive JAVA for example mainActivity

Categories

Resources