M
mc@ey
Neues Mitglied
- 0
Hallo Leute,
Vorhaben:
GPS Loc. ermitteln
Bluetooth Verbindung aufbauen.
Datenbank Verbindung und Übertragung.
Die Programme funktionieren als einzelnes Projekt ( Separate Projekte) gut.
Problem: Ich möchte die einzelne Programme verbinden und möchte die nicht alle in einem Class schreiben. Wie mache ich es am besten?
Mein Code für GPS Loc Ermittlung.
Vorhaben:
GPS Loc. ermitteln
Bluetooth Verbindung aufbauen.
Datenbank Verbindung und Übertragung.
Die Programme funktionieren als einzelnes Projekt ( Separate Projekte) gut.
Problem: Ich möchte die einzelne Programme verbinden und möchte die nicht alle in einem Class schreiben. Wie mache ich es am besten?
Mein Code für GPS Loc Ermittlung.
Code:
package com.example.location;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements LocationListener {
double p1, p2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LocationManager lm =(LocationManager)getSystemService(LOCATION_SERVICE);
String provider = lm.getBestProvider(new Criteria(), true);
lm.requestLocationUpdates( LocationManager.GPS_PROVIDER,0,0, this);
if(provider == null){
onProviderDisabled(provider);
}
}
@Override
public void onLocationChanged(Location location) {
p1= location.getLatitude();
p2= location.getLongitude();
System.out.println(p1);
System.out.println(p2);
}
public double getP1() {
return p1;
}
public double getP2() {
return p2;
}
@Override
public void onProviderDisabled(String provider) {
AlertDialog.Builder builder =new AlertDialog.Builder(this);
builder.setTitle("GPS is Disabled");
builder.setCancelable(false);
builder.setPositiveButton("Enable GPS", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent startGps = new Intent (android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(startGps);
}
});
builder.setNegativeButton("Leave Gps off", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
}