我一直在使用廣播接收器開發一個沒有UI的簡單應用程序。沒有GUI的Android應用程序
該應用程序不包含任何活動。
我給了必要的權限。
我把代碼從這個網址:http://developerandro.blogspot.in/2013/09/check-internet-connection-using.html
該應用程序顯示舉杯「未連接到互聯網」當我點擊改變WiFi狀態。它工作正常。
但我的問題是有一個活動註冊在我的清單文件中,我沒有。所以我從清單中刪除這些行。然後不顯示吐司,我也檢查日誌。沒有輸出更改wifi狀態。
爲什麼發生這種情況?請幫我傢伙...
這裏是清單文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.broadcast_internetcheck"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.broadcast_internetcheck.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.example.broadcast_internetcheck.NetworkChangeReceiver"
android:label="NetworkChangeReceiver" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
</intent-filter>
</receiver>
</application>
</manifest>
這裏是我的廣播接收器類:
public class NetworkChangeReceiver extends BroadcastReceiver{
@Override
public void onReceive(final Context context, final Intent intent) {
String status = NetworkUtil.getConnectivityStatusString(context);
/*Above line will return the status of wifi */
Toast.makeText(context, status, Toast.LENGTH_LONG).show();
}
}
你的意思是你無法連接到互聯網?是這樣嗎? –
這不是我的情況,當我改變我的wifi狀態時,我需要一個簡單的敬酒。 –
所以你想做吐司按鈕,我不是你的代碼,但我會爲你做一個簡單的吐司按鈕? –