没有 GUI 的 Android 应用程序

标签 android broadcastreceiver android-manifest android-wifi

我一直在使用广播接收器开发一个没有 UI 的简单应用程序。

该应用不包含任何 Activity 。

我已授予必要的权限。

我从这个网址获取了代码:http://developerandro.blogspot.in/2013/09/check-internet-connection-using.html

当我点击更改 wifi 状态时,该应用程序显示“未连接到互联网”提示框。它工作正常。

但我的问题是我的 list 文件中注册了一个我没有的 Activity 。所以我从 list 中删除了这些行。然后没有显示 toast ,我也检查了日志。更改 wifi 状态时没有输出。

为什么会这样?请帮帮我...

这是 list 文件:

<?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>

这是我的 Broadcastreceiver 类:

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();

     }
}

最佳答案

关于没有 GUI 的 Android 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21772458/

相关文章:

Android 显示来自 BroadcastReceiver 的通知

java - Android 将字符串写入广播接收器中的文件

java - 如何在 Android 中使用菜单从主 Activity 打开 Intent(MapView)

android - 当 anyDensity ="false"时,菜单列表超出屏幕

android - 如何覆盖库中 Activity 的 screenOrientation 属性

android - 如何在 Firebase Analytics 中查看所有设备列表?

java - 下面的代码有什么问题?

Android Proximity 警报未触发

Android Button 文字定位

java - 如何从 Android 中的 URI 获取文件?