위치 업데이트를 받고이를 보류중인 의도로 보내려고합니다. 이미 잘하고 있습니다. 내가이 위치 업데이트를 받고 중지 할의 언론, 여기에 내 코드 인 경우에는 버튼, 거기 : 코드가 pendingIntent 전화를 계속 어떤 이유로FusedLocationApi에서 업데이트를 제거 할 수 없습니다.
MainActivity
public class MainActivity extends Activity implements LocationListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
GoogleApiClient mGoogleClient;
PendingIntent pendingIntent;
LocationRequest locationRequest;
LocationServices locationServices;
...
protected void onStart() {
super.onStart();
mGoogleClient.connect();
}
@Override
protected void onStop() {
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleClient, pendingIntent);
super.onStop();
}
@Override
public void onLocationChanged(Location location) {
// this callback is invoked when location updates
}
@Override
public void onConnected(Bundle connectionHint) {
try {
locationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setFastestInterval(30000)
.setInterval(60000);
pendingIntent = PendingIntent.getService(this, 0,
new Intent(this, MyLocationHandler.class),
PendingIntent.FLAG_UPDATE_CURRENT);
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleClient, locationRequest, pendingIntent);
//Toast.makeText(this, "Adding Toast", Toast.LENGTH_LONG).show();
} catch (Exception e) {
...
}
}
@Override
public void onConnectionSuspended(int cause) {
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
// this callback will be invoked when the connection attempt fails
if (connectionResult.hasResolution()) {
// Google Play services can fix the issue
// e.g. the user needs to enable it, updates to latest version
// or the user needs to grant permissions to it
try {
connectionResult.startResolutionForResult(this, 0);
} catch (IntentSender.SendIntentException e) {
// it happens if the resolution intent has been canceled,
// or is no longer able to execute the request
}
} else {
// Google Play services has no idea how to fix the issue
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGoogleClient = new GoogleApiClient.Builder(this, this, this)
.addApi(LocationServices.API)
.build();
TrackBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
bTrack = !bTrack;
CheckTrack();
}
}
});
}
...
public void CheckTrack() {
if (a == null) {
a = tracker.getLocation();
}
if (bTrack) {
mGoogleClient.connect();
} else {
DisconnectHandlerCheck.postDelayed(DisconnectRunnableCheck, 500); }
}
}
Handler DisconnectHandlerCheck = new Handler();
Runnable DisconnectRunnableCheck = new Runnable() {
@Override
public void run() {
try {
onStop();
} catch (Exception e) {
...
}
}
};
}
나는 구글은 분리 후에도 클라이언트뿐만 아니라 업데이 트를 제거합니다.
왜 아이디어가 필요합니까?
나는 그것을 시험해 보았다. 그리고 아직도 it wouldnt는 일한다. – user3862636