private void readTextFileAsset(){
new Thread(new Runnable()
{
public void run()
{
// never delete this file in host (test-asin-id)
try {
new ReadTextTaskAsset().execute( "key.txt");
} catch (Exception e) {
//textView.setText("Error : Please check your internet connection " + e.toString());
}
}
}).start();
}
@SuppressLint("StaticFieldLeak")
private class ReadTextTaskAsset extends AsyncTask<String, Void, String> {
@SuppressLint("SetTextI18n")
@Override
protected String doInBackground(String... filename) {
//splashstatus.setText("Reading Text Asset....do in background");
contents = Utils.getTextFromAsset(context, "key.txt");
/*
try{
final InputStream file = getAssets().open(Arrays.toString(filename));
BufferedReader reader = new BufferedReader(new InputStreamReader(file));
String str;
while ((str = reader.readLine()) != null) {
contents.add(str);
}
reader.close();
} catch (MalformedURLException e) {
return "Error : MalformedURLException " + e.toString();
//e.printStackTrace();
} catch (IOException e) {
return "Error : IOException " + e.toString();
} catch (Exception e) {
return "Error : Please check your internet connection " + e.toString();
}
return "null";
*/
return null;
}
@SuppressLint("SetTextI18n")
@Override
protected void onPostExecute(String result) {
getListFromContent();
gotoNextActivity();
}
}
No comments:
Post a Comment