• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

parse KML list files on android

Good evening I'm facing a problem in my code. I would like to parse a set of kml file to extract the contents and put it in bae of data. it returns each time the list of files, but not the contents of each file. Please help me

Here my MainActivity.java file content :


public class MainActivity extends AppCompatActivity {

private TextView txt;

private TextView texte;
ListView listView;
private List<String> fileNameList;
private FlAdapter mAdapter;
private File file;

@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED){
//FetchImages();
listView = (ListView) findViewById(R.id.listView);
file = Environment.getExternalStorageDirectory();
fileNameList = getFileListfromSDCard();
mAdapter = new FlAdapter(this, R.layout.mylist, fileNameList);
listView.setAdapter(mAdapter);

}
else{

ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
}
}
else{
//startActivity(new Intent(getActivity(), SQLite2ExcelActivity.class));
}
}

private List<String> getFileListfromSDCard() {
String state = Environment.getExternalStorageState();
ArrayList<String> filenames = new ArrayList<String>();
String path = Environment.getExternalStorageDirectory()
+ File.separator + "Fodecc_csv";

File directory = new File(path);
File[] files = directory.listFiles();


for (int i = 0; i < files.length; i++)
{
if(files.isFile() && files.getPath().endsWith(".kml")){
String file_name = files.getName();

// you can store name to arraylist and use it later
filenames.add(file_name);

XmlPullParserFactory parserFactory;

try {

parserFactory = XmlPullParserFactory.newInstance();

XmlPullParser parser = parserFactory.newPullParser();

//File file = new File("/storage/emulated/0/Kml.kml");
InputStream is = new FileInputStream(file_name);
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);

parser.setInput(is, null);



processParsing(parser);

//InputStream is = getAssets().open("kml.xml");



} catch (XmlPullParserException e) {



} catch (IOException e) {

}

}

}
return filenames;
}

private void processParsing(XmlPullParser parser) throws IOException, XmlPullParserException{
ArrayList<coordonnees> coordo = new ArrayList<>();

int eventType = parser.getEventType();

coordonnees currentcoordo= null;



while (eventType != XmlPullParser.END_DOCUMENT) {

String eltName = null;



switch (eventType) {

case XmlPullParser.START_TAG:

eltName = parser.getName();



if ("Placemark".equals(eltName)) {

currentcoordo = new coordonnees();

coordo.add(currentcoordo);

} else if (currentcoordo != null) {

if ("name".equals(eltName)) {

currentcoordo.name = parser.nextText();

}

}

break;

}



eventType = parser.next();

}



printcoordo(coordo);
}

private void printcoordo(ArrayList<coordonnees> coordo) {
StringBuilder builder = new StringBuilder();



for (coordonnees Placemark : coordo) {

builder.append(Placemark.name).append("\n");

}

txt = (TextView) findViewById(R.id.te);


txt.setText(builder.toString());
}

}

Help Cannot see zip file in Bluestacks Media Manager

Hi folks, new here.

A problem i am experiencing is, i use Viber, and i archive my messages, and it creates a zip file in Viber. However, i don't see it in Media Manager. The previous time it worked.

I have no idea what's going on. Exporting to windows is the easy part. Having it appear in Media Manager, that's a different story.

Please assist
Thanks in advance

I do not hear any sound now when I make phone calls

Somebody told me to blow some compressed air into the earpiece to try and remove any junk that had built up, and see what happens. Well I just happened have an old can Blow Off Duster laying around, that I haven't used in years. So I blew the compress air into the earpiece hole, and guess what? The sound works fine now !
Excellent! I'm glad you're back in business, and appreciate that you posted your solution. It will likely help someone else down the road.

Filter

Back
Top Bottom