Can't bind to local 8601 for debugger
ddmlib] An established connection was aborted by the software in your host machine
java.io.IOException: An established connection was aborted by the software in your host machine
public class My_location_activity extends Activity implements ConnectionCallbacks,
OnConnectionFailedListener
{
@Override protected void onCreate(Bundle savedInstanceState)
{
}
@Override protected void onStart()
{
}
@Override protected void onStop()
{
}
@Override public void onConnected(Bundle con_bundle)
{
}
@Override public void onConnectionFailed(ConnectionResult provider)
{
}
@Override public void onConnectionSuspended(int arg0)
{
}
}
@Override protected void onCreate(Bundle savedInstanceState)
{
GoogleApiClient api_client = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
@Override protected void onStart()
{
super.onStart();
api_client.connect();
}
@Override protected void onStop()
{
super.onStop();
api_client.disconnect();
}
@Override public void onConnectionSuspended(int arg0)
{
api_client.connect();
}
@Override public void onConnected(Bundle con_bundle)
{
Location location = LocationServices.FusedLocationApi.getLastLocation(api_client);
}
This is the bare bones of the new API and I was doing something wrong. Permissions have changed in Marshmallow (Android 6.0). Setting the permissions in the manifest is no longer enough; it still has to be done but each activity in each app now has to ask for the permissions that have been requested in the manifest. There is documentation on this but, considering it is such a monumental shift of direction, I expected a lot more. There are methods on selecting individual permissions to allow the user to customise the app, but I just wanted to get it working. So in onCreate() I added
int prems = checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION);
if (perms != PackageManager.PERMISSION_GRANTED)
{
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.INTERNET,
Manifest.permission.ACCESS_NETWORK_STATE}, 1);
}
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)