I have a BroadcastReciever and a Service. When a Internet connection established it has to start service that download some data.
My BroadcastReceiver
public class NetworkStateListener extends BroadcastReceiver
{
@Override
public void onReceive(Context c, Intent intent)
{
Toast.makeText(c,"started",Toast.LENGTH_SHORT).show();
c.startService(new Intent(c,DataDownloader.class));
// TODO: Implement this method
}
}
Here is some codes of Manifest...
<receiver android:name="com.Example.SGSN.worker.NetworkStateListener"
android:enabled="true">
<intent-filter android:priority="999">
<action android:name="android.net.wifi.WifiManager.NETWORK_STATE_CHANGED_ACTION"/>
<action android:name="android.net.wifi.WIFI_STATE_CHANGED"/>
<action android:name="android.net.wifi.WifiManager.SUPLICANT_STATE_CHANGED_ACTION"/>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>
and requested permissions...
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Not even a single action is got triggered. I dont know where I committed mistake.I have also searched for answers but my problem not solved. The BroadcastReceiver works when I register it in activity dynamically. I need it in background. Someone help please.
You should remove:
android:process=":channel"
UPD
Here code of manifest which is 100% working:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.andrey.test">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main2">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<receiver
android:name=".MyReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.net.wifi.WifiManager.NETWORK_STATE_CHANGED_ACTION" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
<action android:name="android.net.wifi.WifiManager.SUPLICANT_STATE_CHANGED_ACTION" />
<action android:name="android.net.conn.CONNECTIVITY_ACTION" />
</intent-filter>
</receiver>
</application>
</manifest>