2017-02-05 1 views
0

이제 Android 위치 응용 프로그램을 사용하려고합니다.하지만이 소스 코드에서 라이브러리를 가져올지라도 AsyncTask를 확장 할 수 없습니다.AsyncTask를 확장하는 중 오류가 발생했습니다.

이 코드는 다른 사람의 의견에서 찾았습니다. 나는이 오류를 시도하고 보여주었습니다.

Error:(90, 5) error: LocServ.SendToServer is not abstract and does not override abstract method doInBackground(String...) in AsyncTask


package com.example.user.locserv; 
import android.app.Activity; 
import android.support.annotation.Nullable; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.app.IntentService; 
import android.app.Service; 
import android.content.Context; 
import android.content.Intent; 
import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager; 
import android.os.AsyncTask; 
import android.os.Handler; 
import android.os.IBinder; 
import android.os.Looper; 
import android.os.SystemClock; 
import android.util.Log; 
import android.widget.Toast; 
import org.apache.http.message.BasicNameValuePair; 
import org.apache.http.NameValuePair; 
import org.json.JSONObject; 
import java.util.ArrayList; 
import java.util.List; 
import java.util.Timer; 
import java.util.TimerTask; 
import android.support.v4.app.FragmentActivity; 

public class LocServ extends Service implements LocationListener { 
    private static String url_insert_location = "http://172.20.10.4/testing/insert.php"; 
    public static String LOG = "Log"; 

    JSONObject jsonParser = new JSONObject(); 

    private Context mContext; 

    boolean isGPSEnabled = false; 
    boolean isNetworkEnabled = false; 
    boolean canGetLocation = false; 
    Location location; 
    double latitude; 
    double longitude; 

    private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 0; 

    private static final long MIN_TIME_BW_UPDATES = 1000; 

    protected LocationManager locationManager; 

    public LocServ(Context context) { 
     this.mContext = context; 
    } 

    public LocServ() { 
     super(); 
     mContext = LocServ.this; 
    } 


    @Nullable 
    @Override 
    public IBinder onBind(Intent intent) { 
     return null; 
    } 

    @Override 
    public int onStartCommand(Intent intent, int flags, int startId) { 
     Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show(); 
     Log.i(LOG, "Service started"); 
     Log.i("asd", "This is sparta"); 

     new SendToServer().execute(Double.toString(getLocation().getLongitude()), Double.toString(getLocation().getLatitude())); 
     return START_STICKY; 
    } 

    @Override 
    public void onCreate() { 
     super.onCreate(); 
     Log.i(LOG, "Service created"); 

    } 

    @Override 
    public void onDestroy() { 
     super.onDestroy(); { 
      Log.i(LOG, "Service destroyed"); 
     } 
    } 

    class SendToServer extends AsyncTask<String,String,String> { 
     @Override 
     protected String doInBackGround(String... la) { 
      try { 
       Log.i("string", la[0]); 
       String longi = la[0]; 
       String lati = la[1]; 

       Log.d("value", lati); 
       Log.d("value", longi); 
       ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(); 
       params.add(new BasicNameValuePair("longitude", longi)); 
       params.add(new BasicNameValuePair("latitude", lati)); 

       JSONObject json = jsonParser.makeHttpRequest(url_insert_location, "POST", params); 
       Log.d("Create Response", json.toString()); 
      } catch (Exception e) { 
       Log.i("error", e.toString()); 
      } 
      return "call"; 
     } 

    } 

    public Location getLocation(){ 
     try{ 
      locationManager= (LocationManager) mContext.getSystemService(LOCATION_SERVICE); 
      isGPSEnabled=locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); 
      isNetworkEnabled=locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); 

      if(!isGPSEnabled && !isNetworkEnabled){ 

      } 
      else{ 
       this.canGetLocation=true; 
        if(isNetworkEnabled){ 

         locationManager.requestLocationUpdates(
           LocationManager.NETWORK_PROVIDER,MIN_TIME_BW_UPDATES,MIN_DISTANCE_CHANGE_FOR_UPDATES, 
           this); 
         Log.d("Network","Network"); 
         if(locationManager != null){ 
          location=locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
          if(location != null){ 
           latitude=location.getLatitude(); 
           longitude=location.getLongitude(); 
          } 
         } 
        } 
       if(isGPSEnabled){ 
        if(location==null){ 
         locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,MIN_TIME_BW_UPDATES,MIN_DISTANCE_CHANGE_FOR_UPDATES,this); 
         Log.d("GPS Enabled","GPS Enalbled"); 
         if(locationManager!=null){ 
          location=locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
          if(location!=null){ 
           latitude=location.getLatitude(); 
           longitude=location.getLongitude(); 
          } 
         } 
        } 
       } 
      } 

     }catch (Exception e){ 
      e.printStackTrace(); 
     } 
     return location; 

    } 

    @Override 
    public void onLocationChanged(Location location) { 
     new SendToServer().execute(Double.toString(getLocation().getLongitude()),Double.toString(getLocation().getLatitude())); 

    } 

    @Override 
    public void onStatusChanged(String provider, int status, Bundle extras) { 

    } 

    @Override 
    public void onProviderEnabled(String provider) { 

    } 

    @Override 
    public void onProviderDisabled(String provider) { 

    } 
} 
+0

를이 코드를 사용하고는, 전체 코드를 추가하세요 ~ – W4R10CK

+0

여기에 코드 –

+0

입니다 Asynctask를 확장하는 동안 오류가 무엇입니까? – W4R10CK

답변

2

Relpace이 :이

doInBackGround  // [g] does not start with capital letter 

:.

doInBackground 
+0

고마워요, 그걸 발견했습니다. –

+0

@AtefHares, Good catch man. +1! – W4R10CK

+0

확장 할 수 있지만 JSONObject json = jsonParser.makeHttpRequest (url_insert_location, "POST", params)에있는 오류가 하나 더 있습니다. –

관련 문제