我正在出于某种测试目的root
使用服务创建WakefulBroadcastReceiver
方法(请注意,我只是通过Activity启动服务器进行了测试,发生了相同的事情):
MyService.java
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(TAG, "Server starting");
// Create the server
server = new WebServer(6666);
new Thread(new Runnable() {
@Override
public void run() {
try {
server.start();
} catch (IOException e) {
Log.d(TAG, e.getMessage());
}
}
}).start();
...
return START_STICKY;
}
WebServer.java:
public class WebServer extends NanoHTTPD {
@Override
public Response serve(IHTTPSession session) {
Log.d(TAG, "Serving");
return new NanoHTTPD.Response("<html><body>test</body></html>");
}
我在/ system / app中push
使用adb
APK,因此可以在不先使用活动的情况下调用该服务。然后重新启动外壳。
我可以看到服务器等待连接的日志,然后:
wget http://127.0.0.1:6666
用adb shell
,我可以看到日志“服务”。localhost
过),则无法访问服务器。我使用API18和默认的Nexus7 AVD(也尝试Genymotion
过使用三星平板电脑),但没有任何效果。网络设置中没有配置代理。
我不明白为什么浏览器(在设备上)无法到达我的6666
端口127.0.0.1
(在设备上)
这是清单:
<application android:allowBackup="true" android:label="@string/app_name"
android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme">
<service android:name=".MyService" android:label="Tool" android:enabled="true"/>
<receiver android:name=".receiver.BootCompleteReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
我疯了,最后有人给我发送了这个链接:https : //superuser.com/questions/188058/which-ports-are-considered-unsafe-on-chrome
端口6666被认为是不安全的...我希望将其写在页面上,而不是无法到达服务器。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句