enter code hereTrying to start the service but it is not started on Booting while service is running perfectly during the start of the app for first time.
This is the Receiver and i want use switch case because there is lot many things i have to start using receiver.
@Override
public void onReceive(Context context, Intent intent) {
Intent serviceIntent;
switch (intent.getAction()) {
case SmackService.NEW_MESSAGE:
Log.i("TAG", "processMessage() BroadCast Recieve");
break;
case Intent.ACTION_BOOT_COMPLETED:
Log.i("TAG", "Boot");
Toast.makeText(context, "case", Toast.LENGTH_SHORT).show();
serviceIntent = new Intent(context, SmackService.class);
context.startService(serviceIntent);
break;
}
}
Manifest Content :-
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:name="com.example.abhishek.im.ChatReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="com.tlt.rx.msg" />
</intent-filter>
</receiver>
Service Class
public class SmackService extends Service {
@Override
public void onCreate() {
super.onCreate();
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
user_data = new HashMap<>();
if (intent != null && intent.hasExtra(BUNDLE_MSG_SYNC)) {
doChatSync = intent.getBooleanExtra(BUNDLE_MSG_SYNC, false);
}
if (intent != null) {
String email, password, name;
email = intent.getExtras().getString("email");
password = intent.getExtras().getString("password");
name = intent.getExtras().getString("name");
activity=intent.getExtras().getString("activity");
user_data.put("email", email);
user_data.put("password", password);
user_data.put("name", name);
start(user_data);
}
return Service.START_STICKY;
}
}
Starting the service manually:
Toast.makeText(MainActivity.this, "Signing in", Toast.LENGTH_LONG).show();
Intent intent = new Intent(MainActivity.this, SmackService.class);
intent.putExtra("email", email);
intent.putExtra("password", password);
intent.putExtra("name", name);
intent.putExtra("activity", "MainActivity");
startService(intent);
nt);
Aucun commentaire:
Enregistrer un commentaire