나는 어떤 활동도하지 않는 서비스 중이 야. 그것만 배경에서 일하고. 위도와 경도를 받고 우편으로 보내십시오. 문제는 프로그램이 메일을 보내지 않고 Java Mail API를 사용하고 있다는 것입니다.gps에서 위치를 가져 와서 메일 보내기 서비스 없슴
그것은 주요 활동
public class MainActivity extends Service {
LocationManager lm;
LocationListener lis;
Location loc;
Double lat;
Double lan;
Location location;
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in Meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 10000; // in Milliseconds
LocationManager locationManager;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MINIMUM_TIME_BETWEEN_UPDATES,
MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
new MyLocationListener()
);
sendMail(showcurrentlocation());
}
private String showcurrentlocation() {
// TODO Auto-generated method stub
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
String message = null;
if (location != null) {
message = String.format(
"Current Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
}
return message;
}
public void sendMail(String msg) {
try {
GMailSender sender = new GMailSender("user",
"password");
sender.sendMail("subject",body, "sender",
"recepients");
} catch (Exception e) {
Log.e("SendMail", e.getMessage(), e);
}
}
private class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
String message = String.format(
"New Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
}
public void onStatusChanged(String s, int i, Bundle b) {
Toast.makeText(MainActivity.this, "Provider status changed",
Toast.LENGTH_LONG).show();
}
public void onProviderDisabled(String s) {
Toast.makeText(MainActivity.this,
"Provider disabled by the user. GPS turned off",
Toast.LENGTH_LONG).show();
}
public void onProviderEnabled(String s) {
Toast.makeText(MainActivity.this,
"Provider enabled by the user. GPS turned on",
Toast.LENGTH_LONG).show();
}
}
}
다른 클래스의 방송 수신기
public class MyBroadcastReceiver extends BroadcastReceiver{
public static final String TAG = "LocationLoggerServiceManager";
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent service = new Intent(context, MainActivity.class);
context.startService(service);
}
}public class MyBroadcastReceiver extends BroadcastReceiver{
public static final String TAG = "LocationLoggerServiceManager";
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent service = new Intent(context, MainActivity.class);
context.startService(service);
}
}
무엇이 문제입니까? 어디서 오류가 발생합니까? 컴파일 오류 또는 런타임 오류입니까? LOGCAT을 제공하십시오! – theAlse