Android Geopoint:Sim工具包已停止

时间:2014-07-22 13:39:08

标签: android geolocation sim-toolkit

    Hi Friends today its the second question i am posting in the forum. I am a beginner in programming. So its very hard for me to find the error in the code when nothing is displayed in the Logcat.  
    My problem is i am doing a gps based application to notify me when i reach 10 meters away from a place. but when i install the program me in my device it shows "sim toolkit stopped" and it shuts down ...i am pasting my whole code and console data below this. please have a look and tell me the errors if any.

我实际上是在尝试进行异步任务。但我不确定,我的代码有多远是正确的。请帮帮我。

    MainActivity.java............................................................................................................................................................

    package com.example.mobiletrackerslave;

    import android.content.Intent;
    import android.os.Bundle;
    import android.support.v7.app.ActionBarActivity;
    import android.widget.EditText;


    public class MainActivity extends ActionBarActivity {

        public EditText text1;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
           text1 =(EditText) findViewById(R.id.text1);
            Intent intent = new Intent(this, TrackService.class);

            startService(intent);


        }

        @Override
        protected void onResume() {
            // TODO Auto-generated method stub
            super.onResume();
            finish();
        }


    }




    TrackService.java.......................................................................................................................



    package com.example.mobiletrackerslave;

    import android.app.Activity;
    import android.app.IntentService;
    import android.app.Service;
    import android.content.Context;
    import android.content.Intent;
    import android.location.Location;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.os.IBinder;
    import android.widget.EditText;

    import com.example.android.location.LocationUtils;
    import com.google.android.gms.common.ConnectionResult;
    import com.google.android.gms.common.GooglePlayServicesClient;
    import com.google.android.gms.location.LocationClient;
    import com.google.android.gms.location.LocationListener;
    import com.google.android.gms.location.LocationRequest;

    public class TrackService extends IntentService implements LocationListener,
            GooglePlayServicesClient.ConnectionCallbacks,
            GooglePlayServicesClient.OnConnectionFailedListener {

        //boolean uploaded = false;
        private Context context;
        String Lat, Long;
        // A request to connect to Location Services
        private LocationRequest mLocationRequest;

        //List<?> pkgAppsList;
        //ArrayList<ArrayList<String>> list;
        //Context context;
        //ArrayList<String> iteminserted = new ArrayList<String>();

        private LocationClient mLocationClient;

        // ArrayList<ArrayList<String>> UnUploadedData = new
        // ArrayList<ArrayList<String>>();


        //@Override
        //public IBinder onBind(Intent intent) {
            //return null;
        //}
        //public TrackService() {
            //super("TrackService"); 
         //}
        public TrackService() {
            super("Trackservice"); 

             }



        @Override
        public void onCreate() {
            super.onCreate();
            // Create a new global location parameters object
            mLocationRequest = LocationRequest.create();
            context = getApplicationContext();
            /*
             * Set the update interval
             */
            // mLocationRequest
            // .setInterval(LocationUtils.UPDATE_INTERVAL_IN_MILLISECONDS);
            mLocationRequest.setInterval(1000 * 60 * 2);// Every 2 minute

            // Use high accuracy
            mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

            // Set the interval ceiling to one minute
            mLocationRequest
                    .setFastestInterval(LocationUtils.FAST_INTERVAL_CEILING_IN_MILLISECONDS);
            mLocationClient = new LocationClient(this, this, this);

        }





        /*
         * Called by Location Services when the request to connect the client
         * finishes successfully. At this point, you can request the current
         * location or start periodic updates
         */
        @Override
        public void onConnected(Bundle bundle) {

            startPeriodicUpdates();

        }

        /**
         * Report location updates to the UI.
         * 
         * @param location
         *            The updated location.
         */
        @Override
        public void onLocationChanged(Location location) {
            System.out.println(location.getLatitude() + " "+ location.getLongitude());
            Lat = location.getLatitude() + "";
            Long = location.getLongitude() + "";
            //if (isConnectingToInternet())
                new UploadLocationInfo().execute();
            // if (uploaded)
            // this.stopSelf();
            }

        /**
         * In response to a request to start updates, send a request to Location
         * Services
         */
        private void startPeriodicUpdates() {

            mLocationClient.requestLocationUpdates(mLocationRequest, this);

        }

        /**
         * In response to a request to stop updates, send a request to Location
         * Services
         */
        private void stopPeriodicUpdates() {
            mLocationClient.removeLocationUpdates(this);

        }

        //public boolean isConnectingToInternet() {
            //ConnectivityManager connectivity = (ConnectivityManager) this
                //  .getSystemService(Context.CONNECTIVITY_SERVICE);
            //if (connectivity != null) {
                //NetworkInfo[] info = connectivity.getAllNetworkInfo();
                //if (info != null)
                    //for (int i = 0; i < info.length; i++)
                        //if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                            //return true;
                        //}

            //}
            //return false;
        //}



        public class UploadLocationInfo extends AsyncTask<Void, Void, Void> {


            @Override
            protected Void doInBackground(Void... params) {
                // Uploading Application List
                //ArrayList<NameValuePair> LOCATION = new ArrayList<NameValuePair>();
                //LOCATION.add(new BasicNameValuePair("LAT", Lat));
                //LOCATION.add(new BasicNameValuePair("LONG", Long));

                //TelephonyManager telephonyManager = (TelephonyManager) getApplicationContext()
                    //  .getSystemService(getApplicationContext().TELEPHONY_SERVICE);
                //IMEI = telephonyManager.getDeviceId();
                //LOCATION.add(new BasicNameValuePair("IMEI", IMEI));
                double x = Double.parseDouble(Long);
                double y = Double.parseDouble(Lat);
                EditText text1 = (EditText) ((Activity)context).findViewById(R.id.text1);
                text1.setText("lat"+y+"Log"+x);
                double a = 48.6800000;
                double b = 2.2100000;  
                float[] results = new float[1];
                Location.distanceBetween(y, x, b, a, results);
                float distanceInMeters = results[0];
                boolean isWithin10m = false;
                if( distanceInMeters < 20)
                {
                 isWithin10m = true;
                }



                System.out.println("Uploading New Location");

               if(isWithin10m){

                try {
                    //open a web page


                } catch (Exception e) {
                    e.printStackTrace();
                }
                }else{
                    text1.setText("nothing to display");

                }
                return null;
            }
        }

        @Override
        public void onConnectionFailed(ConnectionResult arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onDisconnected() {
            // TODO Auto-generated method stub

        }
        @Overrideenter code here
        public void onDestroy() {
            // If the client is connected
            System.out.println("Destroy");
            if (mLocationClient.isConnected()) {
                stopPeriodicUpdates();
            }
            // After disconnect() is called, the client is considered "dead".
            mLocationClient.disconnect();

            super.onDestroy();
        }

        @Override
        public IBinder onBind(Intent intent) {
            // TODO Auto-generated method stub
            return null;
        }


        @Override
        protected void onHandleIntent(Intent intent) {
            // TODO Auto-generated method stub

        }








    }



Manifest.XML.....................................................................................................................



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.mobiletrackerslave"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.mobiletrackerslave.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>

                <action android:name="android.intent.action.MAIN" />


                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>
        <service android:name="com.example.mobiletrackerslave.TrackService" ></service>

    </application>

</manifest>

CONSOLE .............................................. .................................................. .............

eTrackerSlave2] ------------------------------
[2014-07-22 15:32:23 - MobileTrackerSlave2] Android Launch!
[2014-07-22 15:32:23 - MobileTrackerSlave2] adb is running normally.
[2014-07-22 15:32:23 - MobileTrackerSlave2] Performing com.example.mobiletrackerslave.MainActivity activity launch
[2014-07-22 15:32:23 - MobileTrackerSlave2] Automatic Target Mode: Unable to detect device compatibility. Please select a target device.
[2014-07-22 15:32:26 - MobileTrackerSlave2] Application already deployed. No need to reinstall.
[2014-07-22 15:32:26 - MobileTrackerSlave2] Starting activity com.example.mobiletrackerslave.MainActivity on device 02121ab5094d43b3
[2014-07-22 15:32:26 - MobileTrackerSlave2] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.mobiletrackerslave/.MainActivity }

0 个答案:

没有答案