hi. I am trying to make an app where I get and store the location of
the user along with some other info entered by the user.
My code is as follows:

package com.DuckTag;

import android.app.Activity;
import android.os.Bundle;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


public class DuckTagActivity extends Activity implements
LocationListener{
    /** Called when the activity is first created. */
        private String type = "Type";
        private String cname = "cname";
        private String snameFirst = "snameFirst";
        private String snameLast = "snameLast";
        private String color = "color";
        private float weight = 0;
        private String location = " ";
        private EditText DuckType;
        private EditText CommonName;
        private EditText ScientificName;
        private EditText Color;
        private EditText Weight;
        private EditText MyLocation;
        private Button Locate;
        private LocationManager locationManager;
        private String bestProvider;
        private static String tag = "dmotion";

        private OnClickListener locateListener = new OnClickListener() {
                public void onClick(View v) {
                        try {
                                Log.e(tag,"tag button clicked");

                                // Store user inputs in class fields
                                type = DuckType.getText().toString();
                        cname = CommonName.getText().toString();
                        snameFirst = ScientificName.getText().toString();
                        snameLast = 
snameFirst.substring(snameFirst.lastIndexOf("
"));
                        snameFirst = snameFirst.substring(0,snameFirst.indexOf("
"));
                        color = Color.getText().toString();
                        weight =
Float.valueOf((Weight.getText().toString()).trim()).floatValue();
                        Locate.setOnClickListener(locateListener);
                        Log.e(tag,"inputs converted to text");

                                //Get user's location
                                locationManager = (LocationManager)
getSystemService(LOCATION_SERVICE);
                                Criteria criteria = new Criteria();
                        bestProvider = locationManager.getBestProvider(criteria,
false);
                        Log.e(tag,bestProvider);
                                Location currentLocation =
locationManager.getLastKnownLocation(bestProvider);
                                if(currentLocation != null) {
                                        Toast.makeText(getApplicationContext(), 
"not null",
Toast.LENGTH_LONG);
                                        location = 
Double.toString(currentLocation.getLatitude()) + " " +
Double.toString(currentLocation.getLongitude());
                                        Toast.makeText(getApplicationContext(), 
location,
Toast.LENGTH_LONG);
                                        MyLocation.setText(location);
                                }
                                else {
                                        Toast.makeText(getApplicationContext(), 
"null",
Toast.LENGTH_LONG);
                                        Log.e(tag,"currentLocation is null");
                                }
                        } catch (Exception e) {
                                Log.e(tag,e.getMessage());
                        }
                }

        };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Log.e(tag, "activity created");
        try {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        DuckType = (EditText) findViewById(R.id.DuckType);
        CommonName = (EditText) findViewById(R.id.CommonName);
        ScientificName = (EditText) findViewById(R.id.Scientificame);
        Color = (EditText) findViewById(R.id.Color);
        Weight = (EditText) findViewById(R.id.Weight);
        MyLocation = (EditText) findViewById(R.id.MyLocation);
        Locate = (Button) findViewById(R.id.Locate);
        Locate.setOnClickListener(locateListener);
        Log.e(tag,"xml objects assigned");

        /*
         * type = DuckType.getText().toString();
         * cname = CommonName.getText().toString();
         * snameFirst = ScientificName.getText().toString();
         * Log.e(tag,Integer.toString(snameFirst.lastIndexOf(" ")));
         * snameLast = snameFirst.substring(snameFirst.lastIndexOf("
"));
         * Log.e(tag,"1");
         * snameFirst = snameFirst.substring(1,snameFirst.indexOf("
"));
         * Log.e(tag,"2");
         * color = Color.getText().toString();
         * weight =
Float.valueOf((Weight.getText().toString()).trim()).floatValue();
         * Locate.setOnClickListener(locateListener);
         * Log.e(tag,"inputs converted to text");
         */

        } catch (Exception e) {
                Log.e(tag,e.toString());
                Log.e(tag,e.getMessage());
                }

    }

        public void onLocationChanged(Location location) {
                // TODO Auto-generated method stub

        }

        public void onProviderDisabled(String provider) {
                // TODO Auto-generated method stub

        }

        public void onProviderEnabled(String provider) {
                // TODO Auto-generated method stub

        }

        public void onStatusChanged(String provider, int status, Bundle
extras) {
                // TODO Auto-generated method stub

        }
}

My android manifest is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android";
      package="com.DuckTag"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

        <uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />
        <uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION" />


    <application android:icon="@drawable/icon" android:label="@string/
app_name">
        <activity android:name=".DuckTagActivity"
                  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>
</manifest>

I am getting a Socket exception: address family not supported by
protocol error when I try to send location from emulator controller in
DDMS perspective in Eclipse. Does my code achieve the objective? Where
am I going wrong?

-- 
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