I've made my first android service, I want that service to be launched at boot but doesn't work
Here is the service class
package service.com.serviceboot;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
public class ServiceBoot extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
Toast.makeText(this, "Servicio creado", Toast.LENGTH_LONG).show();
Log.d("SERVICEBOOT", "Servicio creado");
}
@Override
public void onDestroy(){
super.onDestroy();
Toast.makeText(this, "Servicio destruido", Toast.LENGTH_LONG).show();
Log.d("SERVICEBOOT", "Servicio destruido");
}
}
This is the broadcast receiver
package service.com.serviceboot;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class ReceiverBoot extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent serviceIntent = new Intent(context, ServiceBoot.class);
context.startService(serviceIntent);
}
}
and the manifest
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application android:allowBackup="true" android:label="@string/app_name"
android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme">
<service
android:name=".ServiceBoot">
</service>
<receiver android:name=".ReceiverBoot" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
I rebbot the phone but the service is not lanched