im having some errors in my code, i want it to check the location
using the best available provider (GPS, network, internet...) and
returns it back to a server and then request an image from the server,
the server will be the link that is in the code its a picture but ill
change the server late on to the schools server so on this 1 you wont
be able to send any thing to it but i need it in the code

this is the manifest file:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://
schemas.android.com/apk/res/android" package="com.paad.whereami">
<application android:icon="@drawable/icon"> <activity
android:name=".WhereAmI" android:label="@string/app_name"> <intent-
filter> <action android:name="android.intent.action.MAIN" /> <category
android:name="android.intent.category.LAUNCHER" /> </intent-filter> </
activity> </application> <uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />
android:name="android.permission.INTERNET <uses-permission
android:name="android.permission.INTERNET"></uses-permission> <uses-
permission android:name="android.permission.ACCESS_COARSE_LOCATION"></
uses-permission> </manifest>

Main.xml:

'

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android";
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/myLocationText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"/>
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</LinearLayout>

'

package com.paad.whereami;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

import android.app.Activity;
import android.content.Context;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;

import android.app.Activity;
import android.os.Bundle;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.text.format.Time;
import android.widget.ImageView;
import android.widget.Toast;
import java.util.Timer;

import com.simple.me.R;

import android.os.SystemClock;





public class WhereAmI extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

LocationManager locationManager;
String context = Context.LOCATION_SERVICE;
locationManager = (LocationManager)getSystemService(context);

Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
criteria.setSpeedRequired(true);
String provider = locationManager.getBestProvider(criteria, true);

Location location = locationManager.getLastKnownLocation(provider);
updateWithNewLocation(location);

locationManager.requestLocationUpdates(provider, 2000, 1,
locationListener);
}

private final LocationListener locationListener = new
LocationListener() {
public void onLocationChanged(Location location) {
updateWithNewLocation(location);
}

public void onProviderDisabled(String provider){
updateWithNewLocation(null);
}

public void onProviderEnabled(String provider){ }
public void onStatusChanged(String provider, int status,
Bundle extras){ }
};

private void updateWithNewLocation(Location location) {
String latLongString;
TextView myLocationText;
myLocationText = (TextView)findViewById(R.id.myLocationText);

String addressString = "No address found";

setContentView(R.layout.main);
Bitmap bitmap = DownloadImage(
"http://blogs.ocweekly.com/navelgazing/boston.jpg";);
ImageView img = (ImageView) findViewById(R.id.img);
img.setImageBitmap(bitmap);

}

private Bitmap DownloadImage(String URL) {
Bitmap bitmap = null;

InputStream in = null;

try {
in = OpenHttpConnection(URL);
bitmap = BitmapFactory.decodeStream(in);
in.close();
} catch (IOException e1) {
e1.printStackTrace();
}
return bitmap;
}
private InputStream OpenHttpConnection(String urlString) throws
IOException {
InputStream in = null;
int response = -1;

URL url = new URL(urlString);
URLConnection conn = url.openConnection();

if (!(conn instanceof HttpURLConnection))
throw new IOException("Not an HTTP connection");
try{
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("GET");
httpConn.connect();

response = httpConn.getResponseCode();
if (response == HttpURLConnection.HTTP_OK) {
in = httpConn.getInputStream();
}
} catch (Exception ex) {
throw new IOException("Error connecting");
}
return in;
}



else {
latLongString = "No location found";
}
myLocationText.setText("Your Current Position is:\n" +
latLongString + "\n" );
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to