Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[창현]프래그먼트 #70

Open
lch8609 opened this issue Sep 14, 2017 · 2 comments
Open

[창현]프래그먼트 #70

lch8609 opened this issue Sep 14, 2017 · 2 comments

Comments

@lch8609
Copy link

lch8609 commented Sep 14, 2017

No description provided.

@lch8609
Copy link
Author

lch8609 commented Sep 17, 2017

public class GpsService extends Service implements LocationListener {
public static double lat;
public static double lng;

private LocationManager locationManager;
private String provider;

private boolean isGPS = false;

void permissionAnswer(){
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
}
void GPSinit() {
    Log.e("test", "GPSinit()");
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    // Get the location manager
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // Define the criteria how to select the locatioin provider -> use
    // default
    Criteria criteria = new Criteria();
    provider = locationManager.getBestProvider(criteria, false);


    Location location = locationManager.getLastKnownLocation(provider);

    // Initialize the location fields
    if (location != null) {
        System.out.println("Provider " + provider + " has been selected.");
        onLocationChanged(location);
    } else {
    }

    if (false == isGPS) {
        isGPS = !isGPS;
        locationManager.requestLocationUpdates(provider, 400, 1, this);
    }
}

@Nullable
@Override
public IBinder onBind(Intent intent) {
    //액티비티간 통신할때 쓰임
    return null;
}

@Override
public void onCreate() {
    Log.e("test", "GPS: onCreate()");
    super.onCreate();
    lat = lng = 0.0;

    GPSinit();

}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.e("test", "GPS: onStartCommand()");
    //서비스 호출될때마다 실행
    if (false == isGPS) {
        isGPS = !isGPS;
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
                ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            permissionAnswer();
        }
        locationManager.requestLocationUpdates(provider, 400, 1, this);
    }
    return super.onStartCommand(intent, flags, startId);
}

@Override
public void onDestroy() {
    Log.e("test", "GPS: onDestroy()");
    super.onDestroy();
    if(true == isGPS)
        isGPS = !isGPS;
    locationManager.removeUpdates(this);
}



@Override
public void onLocationChanged(Location location) {
    Log.e("test", "GPS: onLocationChanged()");
    this.lat = (location.getLatitude());
    this.lng = (location.getLongitude());
    Log.e("test", "lat : " + this.lat +", lng : "+this.lng);
}

@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
    Log.e("test", "onStatusChanged");
    if (false == isGPS) {
        isGPS = !isGPS;
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
                ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            permissionAnswer();
        }
        locationManager.requestLocationUpdates(provider, 400, 1, this);
    }
}

@Override
public void onProviderEnabled(String s) {
    Log.e("test", "onProviderEnabled");
    Toast.makeText(this, "Enabled new provider " + provider,
            Toast.LENGTH_SHORT).show();
    if (false == isGPS) {
        isGPS = !isGPS;
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
                ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            permissionAnswer();
        }
        locationManager.requestLocationUpdates(provider, 400, 1, this);
    }
}

@Override
public void onProviderDisabled(String s) {
    Log.e("test", "onProviderDisabled");
    Toast.makeText(this, "Disabled provider " + provider,
            Toast.LENGTH_SHORT).show();
    if(true == isGPS)
        isGPS = !isGPS;
    locationManager.removeUpdates(this);
}

}

서비스호출이 안됨....

09-18 01:43:18.165 11020-11020/com.thatzit.changhyun.fragment_ex E/BoostFramework: BoostFramework() : Exception_1 = java.lang.ClassNotFoundException: Didn't find class "com.qualcomm.qti.Performance" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib64, /vendor/lib64]]

이런 익셉션이뜸....

@lch8609
Copy link
Author

lch8609 commented Sep 18, 2017

https://github.com/lch8609/ServiceException.git
위에 소스프로젝트 통으로 옮김,,,

헬프헬프

@kishe89

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant