mardi 19 mai 2015

Broadcast receiver is not getting invoked

I have used a Broadcast Receiver which is to be invoked when it finds internet Connection on the android device, to check if the Broadcast Receiver is running or not I have tried printing it in the logcat. I have no message being displayed. I am invoking a service in my broadcast receiver which is also not getting invoked. I have seen similar questions on stack overflow but still I am unable to solve the issue. I am stuck with this since many days. Can anybody help me solve this problem?

This is my Broadcast receiver:

public final class ConnectivityReceiver extends BroadcastReceiver
{

    @Override
    public void onReceive(Context context, Intent intent)
    {
        Log.e("BRRRRRRRRRR","works!!!! In Broadcast Receiver...!!!");


        final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        final PendingIntent wakeupIntent = PendingIntent.getService(context, 0,
                new Intent(context, LocationUpdate.class), PendingIntent.FLAG_UPDATE_CURRENT);

       final boolean hasNetwork = !intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
        if (hasNetwork)
        {

            // start service now for doing once
            context.startService(new Intent(context, LocationUpdate.class));

            // schedule service for every 15 minutes
            alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                    SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_FIFTEEN_MINUTES,
                    AlarmManager.INTERVAL_FIFTEEN_MINUTES, wakeupIntent);
        }
        else
        {
            alarmManager.cancel(wakeupIntent);
        }

    }
 }

Manifest.xml

 <receiver    android:name="info.androidhive.loginandregistration.ConnectivityReceiver" >
    <intent-filter>
        <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
        <action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
    </intent-filter>
</receiver>

Aucun commentaire:

Enregistrer un commentaire