Galera, ta dando isso no meu
Exported service does not require permission
Segue o mesmo. O que pode ser isso?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.br.aquavendas"
android:versionCode="1"
android:versionName="1.0" >
<!--
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
-->
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Login"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".CadastrarCliente" android:label="Cadastrar Clientes" />
<activity
android:name=".EditarClientes" android:label="Editar Clientes" >
<intent-filter>
<action android:name="EdicaoCliente" ></action>
<category android:name="android.intent.category.DEFAULT"></category>
</intent-filter>
</activity>
<activity android:name=".Main" android:label="Principal" />
<activity android:name=".Listar" android:label="Lista de Clientes" />
<activity android:name=".ListarProduto" android:label="Lista de Produtos" />
<activity android:name=".ListarVenda" android:label="Lista de Vendas" />
<activity android:name=".Vendas" android:label="Venda de Produtos" />
<activity android:name=".Config" android:label="Configurações" />
<service android:name=".ExportarVendasService">
<intent-filter>
<action android:name="INICIAR_REPLICACAO"></action>
</intent-filter>
</service>
</application>
</manifest>
Galera, dei um Clean no projeto e resolveu. Só que deu outro erro:
11-09 17:42:49.069: E/AndroidRuntime(5179): FATAL EXCEPTION: main
11-09 17:42:49.069: E/AndroidRuntime(5179): java.lang.RuntimeException: Unable to instantiate service com.br.aquavendas.ExportarVendasService: java.lang.InstantiationException: com.br.aquavendas.ExportarVendasService
11-09 17:42:49.069: E/AndroidRuntime(5179): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2943)
11-09 17:42:49.069: E/AndroidRuntime(5179): at android.app.ActivityThread.access$3300(ActivityThread.java:125)
11-09 17:42:49.069: E/AndroidRuntime(5179): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2087)
11-09 17:42:49.069: E/AndroidRuntime(5179): at android.os.Handler.dispatchMessage(Handler.java:99)
11-09 17:42:49.069: E/AndroidRuntime(5179): at android.os.Looper.loop(Looper.java:123)
11-09 17:42:49.069: E/AndroidRuntime(5179): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-09 17:42:49.069: E/AndroidRuntime(5179): at java.lang.reflect.Method.invokeNative(Native Method)
11-09 17:42:49.069: E/AndroidRuntime(5179): at java.lang.reflect.Method.invoke(Method.java:521)
11-09 17:42:49.069: E/AndroidRuntime(5179): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-09 17:42:49.069: E/AndroidRuntime(5179): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-09 17:42:49.069: E/AndroidRuntime(5179): at dalvik.system.NativeStart.main(Native Method)
11-09 17:42:49.069: E/AndroidRuntime(5179): Caused by: java.lang.InstantiationException: com.br.aquavendas.ExportarVendasService
11-09 17:42:49.069: E/AndroidRuntime(5179): at java.lang.Class.newInstanceImpl(Native Method)
11-09 17:42:49.069: E/AndroidRuntime(5179): at java.lang.Class.newInstance(Class.java:1429)
11-09 17:42:49.069: E/AndroidRuntime(5179): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2940)
11-09 17:42:49.069: E/AndroidRuntime(5179): ... 10 more
Chamo assim, no Main.java É uma ListActivity:
Intent intent4 = new Intent("INICIAR_REPLICACAO"); // 5 - Replicar Vendas
intent4.putExtra("itemMenu", itemMenu);
startService(intent4); break;
A classe Service está assim:
package com.br.aquavendas;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import com.br.aquavendas.banco.DB;
//import com.br.aquavendas.dao.VendaDAO;
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;
public class ExportarVendasService extends Service implements Runnable{
private SQLiteDatabase db;
private static Context ctx;
public ExportarVendasService(Context ctx){
this.ctx = ctx;
DB banco =new DB(ctx);
db = banco.getDatabase();
}
public void onCreate(){
new Thread(ExportarVendasService.this).start();
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void run() {
Cursor cursor = db.rawQuery("SELECT * FROM VENDAS", null);
int totalDB = cursor.getCount();
int totalReplicado = 0;
while(cursor.moveToNext()){
StringBuilder strURL = new StringBuilder();
strURL.append("http://192.168.0.100/aquaVendas/inserir.php?data_venda=");
strURL.append(cursor.getString(cursor.getColumnIndex("data_venda")));
strURL.append("&id_cliente=");
strURL.append(cursor.getString(cursor.getColumnIndex("id_cliente")));
strURL.append("&id_produto=");
strURL.append(cursor.getString(cursor.getColumnIndex("id_produto")));
strURL.append("&qtde=");
strURL.append(cursor.getString(cursor.getColumnIndex("qtde")));
strURL.append("&unitario=");
strURL.append(cursor.getString(cursor.getColumnIndex("unitario")));
strURL.append("&desconto=");
strURL.append(cursor.getString(cursor.getColumnIndex("desconto")));
strURL.append("&total=");
strURL.append(cursor.getString(cursor.getColumnIndex("total")));
strURL.append("&vendedor=");
strURL.append(cursor.getString(cursor.getColumnIndex("vendedor")));
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 e){
Log.d("ExportarVendasService", e.getMessage());
}
}
db.close();
if(totalDB == totalReplicado){
}
}
}