Location Manager
25.04.2017 - 12:59
Arkadaşlar hepinize iyi kodlamalar. Benim bir sorunum var. Uygulamamda konum bilgisini almaya çalışıyorum. Kodlamamda sıkıntı yok. İzinleride android 6.0 üstü ne uygun hale getirdim. Ancak bende samsung S4 android 5.0.1 cihazda konum bilgisini alıyorum. Ama GM 5 Plus android 7.0 da alamıyorum. Birde emilatör 4.4 kitkat da konum bilgisi alamıyorum. nedendir. Acaba.
public class MainPermission {
Activity activity = null;
String[] permissions = null;
public MainPermission(Activity activity, String[] permissions) {
this.activity = activity;
this.permissions = permissions;
}
public boolean check() {
if (ContextCompat.checkSelfPermission(this.activity, this.permissions[0]) != PackageManager.PERMISSION_GRANTED) {
return false;
} else {
return true;
}
}
public void request(String message, final int permissionCode) {
final AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.AlertDialogStyle);
builder.setTitle("Test uygulaması");
builder.setMessage(Html.fromHtml(message));
builder.setPositiveButton("Anladım", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
activity.requestPermissions(permissions, permissionCode);
}
}
});
AlertDialog dialogPermissions = builder.create();
dialogPermissions.show();
}
}
public class MainLocation extends Service implements LocationListener {
String lat;
String lon;
public String getLat() {
return lat == null ? "" : lat;
}
public void setLat(String lat) {
this.lat = lat;
}
public String getLon() {
return lon == null ? "" : lon;
}
public void setLon(String lon) {
this.lon = lon;
}
LocationManager locationManager;
Location location;
public MainLocation(Context context) {
locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
if (getLocation(LocationManager.NETWORK_PROVIDER, context) != null) {
location = getLocation(LocationManager.NETWORK_PROVIDER, context);
setLat(String.valueOf(location.getLatitude()));
setLon(String.valueOf(location.getLongitude()));
}
}
public Location getLocation(String provider, Context context) {
if (locationManager.isProviderEnabled(provider)) {
if (ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
locationManager.requestLocationUpdates(provider, 0, 0, this);
if (locationManager != null) {
location = locationManager.getLastKnownLocation(provider);
return location;
}
}
}
return null;
}
@Override
public void onLocationChanged(Location location) {
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:cardview-v7:23.0.+'
compile 'com.android.support:recyclerview-v7:23.0.+'
compile 'com.android.support:support-annotations:23.1.1'
compile 'com.facebook.android:facebook-android-sdk:4.10.0'
compile 'com.google.android.gms:play-services:4.2.42'
// İmageView Oval
compile 'de.hdodenhof:circleimageview:2.0.0'
// Pager
compile 'fr.avianey.com.viewpagerindicator:library:2.4.1.1@aar'
compile 'com.github.bumptech.glide:glide:3.6.0'
compile 'com.nineoldandroids:library:2.4.0'
// İmage Loader
compile 'com.github.bumptech.glide:glide:3.7.0'
}
64
Görüntülenme
0 Beğeni