ハンドラスレッド内のAndroidサービスでこれを使用して、mysqlデータベースに挿入するためにphpページにデータを送信します。URLは問題ありませんが、何らかの理由でphpページに投稿されません。クラス 。
public void onCreate() {
super.onCreate();
// final String mojsadrzaj=new String();
Toast.makeText(this,"Service created ...",Toast.LENGTH_LONG).show();
final SQLiteDatabase db=openOrCreateDatabase("TruckMe", MODE_PRIVATE, null);
db.execSQL("create table if not exists lokacije (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, lokacija VARCHAR(600));");
//regulisanje podataka za logovanje samo prvi put
String idvozaca=new String();
db.execSQL("create table if not exists vozac (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, idvozaca VARCHAR(15));");
Cursor d=db.rawQuery("select idvozaca from vozac", null);
//db.execSQL("delete from vozac;");
if(d.getCount() > 0)
{
d.moveToLast();
idvozaca=d.getString(d.getColumnIndex("idvozaca"));
mojsadrzaj=idvozaca;
Toast t=Toast.makeText(this, "Id vozaca je : " + mojsadrzaj, Toast.LENGTH_LONG);
t.setGravity(Gravity.CENTER, 0, 0);
t.show();
db.close();
}
//regulisanje podataka za logovanje samo prvi put
final Time t=new Time();
//Toast.makeText(this,"Stao kod upita" , Toast.LENGTH_LONG).show();
//deo za thread
final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
public void run() {
if(indikator != 0)
{
try {
URL myURL = new URL(url);
URLConnection myURLConnection = myURL.openConnection();
myURLConnection.connect();
Toast.makeText(MyService.this,"saljem na net "+url , Toast.LENGTH_LONG).show();
}
catch (MalformedURLException e) {
// new URL() failed
// ...
}
catch (IOException e) {
// openConnection() failed
// ...
}
}
indikator=1;
handler.postDelayed(this, 9000);
}
};
//b.setBackgroundColor(Color.RED);
//deo koji naknadno ubacujem za kriterijum
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setPowerRequirement(Criteria.POWER_LOW);
//kraj dela koji sam naknadno ubacio
final LocationManager m=(LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
//deo koji sam takodje ubacio naknadno
String locationprovider =m.getBestProvider(criteria,true);
//deo koji sam takodje ubacio naknadno kraj
LocationListener l=new LocationListener() {
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location arg0) {
String zauzetost=new String();
zauzetost="ZAUZET";
String format="MM/dd/yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(format,Locale.US);
String date= sdf.format(new Date());
t.setToNow();
String longitude=new String();
String latitude=new String();
String speed=new String();
if((int)arg0.getSpeed()==0)
{
speed="0";
}
else
{
speed=""+(((int)arg0.getSpeed()*3600)/1000);
}
longitude=""+ arg0.getLongitude();
latitude=""+ arg0.getLatitude();
Calendar cal=Calendar.getInstance();
url="http://www.compensatemeonline.com/truckmeonline/TruckMeOnline/UnosLokacijaSaTelefona.php?id="+mojsadrzaj+"&longitude="+longitude+"&latitude="+latitude+"&brzina="+speed+"&vreme="+cal.getTime()+"&datum="+date+"&zauzetost="+zauzetost;
// TODO Auto-generated method stub
}
};
// TODO Auto-generated method stub
//pozivanje threada
runnable.run();
//pozivanje threada
m.requestLocationUpdates(locationprovider, 6000, 0, l);
// zamenio sam m.requestLocationUpdates(LocationManager.GPS_PROVIDER, 120000, 0, l); sa m.requestLocationUpdates(locationprovider, 120000, 0, l);
}
これはすべて、アクティビティから実行し、webviewを使用してphpページに投稿すると正常に機能します。しかし、サービスからWebviewを使用できないため、URLを使用しています...、URLが呼び出された後にトーストされたリンクは問題ありません。これの何が問題になっていますか。