S.M_Emamian
S.M_Emamian

Reputation: 17383

IntentService won't start using AlarmManager and broadcastReceiver

I would like to fire an intentservice for echo 5 second periodically . in the my intent service and broadcastreceiver I am using a log.e but I have not any log in logCat :

in my FragmentActivity :

public void scheduleAlarm(Context con) {
        Intent intent = new Intent(con, CheckNotificationPerEach12HourBroadC.class);
        final PendingIntent pIntent = PendingIntent.getBroadcast(con, 0,
            intent, 0);
        long firstMillis = System.currentTimeMillis(); // first run of alarm is immediate
        AlarmManager alarm = (AlarmManager) con.getSystemService(Context.ALARM_SERVICE);
        alarm.setRepeating(AlarmManager.RTC_WAKEUP, firstMillis, intervalMillis, pIntent);
      } 

my BroadcastReceiver :

public class CheckNotificationPerEach12HourBroadC extends BroadcastReceiver{

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    Intent i = new Intent(context, CheckNotificationPerEach12Hour.class);
    Log.e("CheckNotificationPerEach12HourBroadC", "fired");
   // i.putExtra("foo", "bar");
    context.startService(i);
}

}

my IntentService :

public class CheckNotificationPerEach12Hour extends IntentService{

public CheckNotificationPerEach12Hour( ) {
    super("CheckNotificationPerEach12Hour");
    // TODO Auto-generated constructor stub
}

@Override
protected void onHandleIntent(Intent intent) {
    // TODO Auto-generated method stub
    Log.e("intent ser", "10 second");

}

}

in my manifest.xml :

    <receiver 
        android:name="com.shadyab.utilities.CheckNotificationPerEach12HourBroadC"
        android:process=":remote"
        >
    </receiver>  

    <service
        android:name="com.shadyab.utilities.CheckNotificationPerEach12Hour"
        android:exported="false"
         />

Upvotes: 0

Views: 403

Answers (1)

Vibhor Chopra
Vibhor Chopra

Reputation: 657

Create a service, and call it in your broadcast receiver.

public class ServiceTest extends Service {

private Timer mTimer;

@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public void onCreate() {
    super.onCreate();
    // getLogs();

    mTimer = new Timer();
    mTimer.schedule(timerTask, 5000, 5 * 1000);

}


TimerTask timerTask = new TimerTask() {

    @Override
    public void run() {

        Log.wtf("service","running")

    }
};

}

Upvotes: 1

Related Questions