>
ola ele chega abrir o banco mas ta pulando o while onde ele faz o loop para enviar os dados pro webservice ele pula e me mostra o NotificationManager
olha so com ta
package br.com.lubella;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
import br.com.lubella.*;
public class ExportarVendasService extends Service implements Runnable {
public void onCreate() {
System.out.println("esto no oncreate");
new Thread(ExportarVendasService.this).start();
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
System.out.println("esto no onbind");
return null;
}
public void run() {
System.out.println("estou abrindo o banco");
SQLiteDatabase db = openOrCreateDatabase("vendas.db", Context.MODE_PRIVATE, null);
Cursor cursor = db.rawQuery("SELECT * FROM vendas", null);
int totalDB = cursor.getCount();
int totalReplicado = 0;
while(cursor.moveToNext()){
System.out.println("esto no while");
StringBuilder strURL = new StringBuilder();
strURL.append("http://192.168.1.2:80/inserir/pedidos.php?");//trocar pelo servidor certo
strURL.append("&nome=");
strURL.append(cursor.getDouble(cursor.getColumnIndex("nome")));
strURL.append("&preco=");
strURL.append(cursor.getDouble(cursor.getColumnIndex("preco")));
strURL.append("&codigo=");
strURL.append(cursor.getDouble(cursor.getColumnIndex("codigo")));
strURL.append("&quant=");
strURL.append(cursor.getDouble(cursor.getColumnIndex("quant")));
Log.d("ExportarVendasService", strURL.toString());
try{
URL url = new URL(strURL.toString());
HttpURLConnection http = (HttpURLConnection) url.openConnection();
InputStreamReader ips = new InputStreamReader(http.getInputStream());
BufferedReader line = new BufferedReader(ips);
String linhaRetorno = line.readLine();
if(linhaRetorno.equals("Y")){
db.delete("vendas", "_id=?", new String[]{String.valueOf(cursor.getInt(0))});
totalReplicado++;
Log.d("ExportarVendasService", "OK");
}
} catch(Exception ex){
Log.d("ExportarVendasService", ex.getMessage());
}
}
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification nt = null;
if(totalDB == totalReplicado){
nt = new Notification(R.drawable.ic_launcher, "Status Replicação", System.currentTimeMillis());
nt.flags |= Notification.FLAG_AUTO_CANCEL;
PendingIntent p = PendingIntent.getActivity(this, 0, new Intent(this.getApplicationContext(), TelaSplash.class), 0);
nt.setLatestEventInfo(this, "Status Replicação", "A replicação foi feita com sucesso, total: " + totalReplicado, p);
} else {
nt = new Notification(R.drawable.ic_launcher, "Status Replicação", System.currentTimeMillis());
nt.flags |= Notification.FLAG_AUTO_CANCEL;
PendingIntent p = PendingIntent.getActivity(this, 0, new Intent(this.getApplicationContext(), TelaSplash.class), 0);
nt.setLatestEventInfo(this, "Status Replicação", "A replicação não foi feita com sucesso, total: " + totalReplicado + " de " + totalDB, p);
}
nt.vibrate = new long[]{100, 2000, 1000, 2000};
notificationManager.notify((int)Math.round(Math.random()), nt);
db.close();
}
}
Olá
Ele não entra no while? Caso não, a tabela vendas tem registros? E o banco se chama mesmo vendas.db?
obrigado ja resolvi o nome da tabela que tava errado