ConnectivityManager.OnNetworkActiveListener WI-FI问题

时间:2018-10-10 12:45:31

标签: android android-connectivitymanager

我在ConnectivityManager.OnNetworkActiveListener界面上遇到问题,调用了移动数据onNetworkActive()方法,但是当我用 WI-FI 测试它时,没有调用此方法。

我在做什么错? android是否应具有监视WIFI网络连接的权限才能解决此问题?

    @Override
public void onNetworkActive() {
    Log.d(TAG, "onNetworkActive: called");
    if (photos == null || photos.size() < 1) {
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        String queryResult = sharedPreferences.getString(FLICKR_QUERY, "");

        if (queryResult.length() > 0) {
            GetFlickrJsonData getFlickrJsonData = new GetFlickrJsonData("https://api.flickr.com/services/feeds/photos_public.gne", "en-us", true, this);
            getFlickrJsonData.execute(queryResult);
        }
    }
}
  

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.brodeon.flickrbrowser">

    <uses-permission android:name="android.permission.INTERNET" />

    enter code here
    <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.NoActionBar">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".SearchActivity"
            android:label="@string/title_activity_search"
            android:parentActivityName=".MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.brodeon.flickrbrowser.MainActivity" />
            <meta-data android:name="android.app.searchable"
                android:resource="@xml/searchable"/>
            <intent-filter>
                <action android:name="android.intent.action.SEARCH"/>
            </intent-filter>
        </activity>
        <activity
            android:name=".PhotoDetailActivity"
            android:label="@string/title_activity_photo_detail"
            android:parentActivityName=".MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.brodeon.flickrbrowser.MainActivity" />
        </activity>
    </application>

</manifest>

0 个答案:

没有答案