Добрый день!
Я совершенно запутался: когда телефон перезагружается, ресивер должен запустить сервис. Приложение никогда не запускалось? Где поставить этот флаг?
BootBroadcast. java:
package by.minsk.davydov.checkcell;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class BootBroadcast extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Broadcast Intent Detected !",
Toast.LENGTH_LONG).show();
context.startService(new Intent(context, check.class));
}
}
Манифест. xml:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<receiver android:name=".BootBroadcast" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<service android:enabled="true" android:exported="true" android:name=".check"/>
</application>
check. java:
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
public class check extends Service {
final String TAG = "myLogs";
public void onCreate() {
super.onCreate();
Log.i(TAG, "Start check !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
Intent intent = new Intent();
intent.setAction("by.minsk.davydov.checkcell");
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
sendBroadcast(intent);
}
public IBinder onBind(Intent intent) {
return null;
} // arg0
}