The code i am using is:
Using java Syntax Highlighting
- package com.nexgen.threedashone.trainer;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.v4.app.NavUtils;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- //import stuff for web files
- import java.io.BufferedInputStream;
- import java.io.InputStream;
- import java.net.URL;
- import java.net.URLConnection;
- import org.apache.http.util.ByteArrayBuffer;
- public class AboutScreen extends Activity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_about_screen);
- getActionBar().setDisplayHomeAsUpEnabled(true);
- // button handler for return to mainmenu activity
- Button next = (Button) findViewById(R.id.button1);
- next.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- Intent intent = new Intent();
- setResult(RESULT_OK, intent);
- finish();
- }
- });
- //data handler from the web
- /* We will show the data we read in a TextView. */
- // TextView tv = new TextView(this);
- /* Will be filled and displayed later. */
- String version = null;
- try {
- /* Define the URL we want to load data from. */
- URL myURL = new URL(
- "http://www.anddev.org/images/tut/basic/getdatafromtheweb/loadme.txt");
- // "http://db.tt/HGh2uzgf");
- /* Open a connection to that URL. */
- URLConnection ucon = myURL.openConnection();
- /* Define InputStreams to read
- * from the URLConnection. */
- InputStream is = ucon.getInputStream();
- BufferedInputStream bis = new BufferedInputStream(is);
- /* Read bytes to the Buffer until
- * there is nothing more to read(-1). */
- ByteArrayBuffer baf = new ByteArrayBuffer(50);
- int current = 0;
- while((current = bis.read()) != -1){
- baf.append((byte)current);
- }
- /* Convert the Bytes read to a String. */
- version = new String(baf.toByteArray());
- } catch (Exception e) {
- /* On any Error we want to display it. */
- version = e.getMessage();
- }
- /* Show the String on the GUI. */
- TextView textview = (TextView) findViewById(R.id.tvversion);
- textview.setText(version);
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- NavUtils.navigateUpFromSameTask(this);
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
Parsed in 0.016 seconds, using GeSHi 1.0.8.4
I think that should work, but i dont see any result from the textview (named tvversion). If i change the code slightly and remove the variable to just text textview.setText("version"); then the textview is populated with the phrase version as you expect, so i guess my code isnt far off?
I have added <uses-permission android:name="android.permission.INTERNET"></uses-permission> to the manifest, but still no luck.
Any help (with some explanation if possible) would be well received. Do I need to do anything extra when i comes to using the dropbox hosted file as well, or just change the URL?
Thanks;
Andy