Android应用程序没有GUI [英] Android application without GUI
问题描述
我一直在开发利用广播接收器没有用户界面的简单应用程序。
该应用程序不包含任何活动。
我给了必要的权限。
我拿了code从这个网址:http://developerandro.blogspot.in/2013/09/check-internet-connection-using.html
该应用程序显示举杯未连接互联网当我点击的变化wifi的状态。它的正常工作。
但我的问题是有,我没有在我的清单文件中注册的活动。所以我删除我的清单这些行。于是敬酒不显示,我查了日志了。在不断变化的无线状态无输出。
为什么发生这种情况?请帮我家伙...
下面是清单文件:
<?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.broadcast_internetcheck
安卓版code =1
机器人:=的versionName1.0> <用途-SDK
安卓的minSdkVersion =8
机器人:targetSdkVersion =17/> <使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/> <应用
机器人:allowBackup =真
机器人:图标=@绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme>
<活动
机器人:名字=com.example.broadcast_internetcheck.MainActivity
机器人:标签=@字符串/ APP_NAME>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/> <类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT; <接收
机器人:名字=com.example.broadcast_internetcheck.NetworkChangeReceiver
机器人:标签=NetworkChangeReceiver>
&所述;意图滤光器>
<作用机器人:名字=android.net.conn.CONNECTIVITY_CHANGE/>
<作用机器人:名字=android.net.wifi.WIFI_STATE_CHANGED/>
&所述; /意图滤光器>
< /接收器>
< /用途>< /清单>
下面是我的广播接收器类:
公共类NetworkChangeReceiver扩展广播接收器{ @覆盖
公共无效的onReceive(最终上下文的背景下,最终的意图意图){ 字符串状态= NetworkUtil.getConnectivityStatusString(背景);
/ *上面一行将返回无线网络的状态* /
Toast.makeText(上下文,状态Toast.LENGTH_LONG).show(); }
}
您将需要创建一个将在触发服务的虚拟活动的onCreate()
假人,也许非UI与完成的()
。
如果没有所要求的实现是不可能的,尤以上的Android 3.1。
<一个href=\"http://developer.android.com/about/versions/android-3.1.html#launchcontrols\">http://developer.android.com/about/versions/android-3.1.html#launchcontrols
<一href=\"http://stackoverflow.com/questions/14064132/run-only-a-background-service-when-application-start\">Run只有一个后台服务时,应用程序启动结果
没有活动启动Android应用程序结果
<一href=\"http://commonsware.com/blog/2011/07/13/boot-completed-regression-confirmed.html\">http://commonsware.com/blog/2011/07/13/boot-completed-regression-confirmed.html
和更多的服务:结果
<一href=\"http://developer.android.com/guide/components/services.html\">http://developer.android.com/guide/components/services.html
<一href=\"https://developer.android.com/training/run-background-service/create-service.html\">https://developer.android.com/training/run-background-service/create-service.html
<一href=\"http://www.vogella.com/tutorials/AndroidServices/article.html\">http://www.vogella.com/tutorials/AndroidServices/article.html
I have been developing a simple application without UI using broadcast receiver.
The app doesn't contain any ACTIVITIES.
I have given necessary permissions.
I took the code from this url:http://developerandro.blogspot.in/2013/09/check-internet-connection-using.html
The app shows a toast "Not connected to internet" when I click change wifi state. It's working correctly.
But my question is There is an activity registered in my manifest file which I don't have. So I delete those lines from my manifest. Then no toasts are shown and I checked the logs too. No output on changing wifi state.
Why this happened? Please help me guys...
Here is the manifest file:
<?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>
Here is my Broadcastreceiver class:
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();
}
}
You will need to create a dummy activity for a Service which will be triggered in the onCreate()
of the dummy, maybe a non-UI with finish()
.
Without that the required implementation is not possible, esp above Android 3.1.
http://developer.android.com/about/versions/android-3.1.html#launchcontrols
Run only a background service when application start
Start android application without activity
http://commonsware.com/blog/2011/07/13/boot-completed-regression-confirmed.html
And for more on Service:
http://developer.android.com/guide/components/services.html
https://developer.android.com/training/run-background-service/create-service.html
http://www.vogella.com/tutorials/AndroidServices/article.html
这篇关于Android应用程序没有GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!