简体   繁体   English

在移动数据包上运行android APK

[英]Running android APK on mobile data pack

I developed an android application and installed the apk in the device. 我开发了一个android应用程序,并将apk安装在设备中。 It worked fine when it was connected to a contralized wifi router. 将其连接到专用WiFi路由器时,它工作正常。 However the application stopped working when i switched my android device to mobile data pack. 但是,当我将Android设备切换到移动数据包时,该应用程序停止运行。 Should I provide some extra permission apart from <uses-permission android:name="android.permission.INTERNET" /> in the manifest file?? 除清单文件中的<uses-permission android:name="android.permission.INTERNET" />之外,我是否应该提供一些额外的权限?

Help is appreciated. 感谢帮助。 Thanks in advance. 提前致谢。

to perform the network operations described in this lesson, your application manifest must include the following permissions: 要执行本课中描述的网络操作,您的应用程序清单必须包含以下权限:

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

This code snippet tests network connectivity for mobile. 此代码段测试了移动设备的网络连接。 It determines whether these network interfaces are available (that is, whether network connectivity is possible) and/or connected (that is, whether network connectivity exists and if it is possible to establish sockets and pass data): 它确定这些网络接口是否可用(即是否可以进行网络连接)和/或已连接(即是否存在网络连接以及是否可以建立套接字并传递数据):

    private static final String DEBUG_TAG = "NetworkStatusExample";
...      
ConnectivityManager connMgr = (ConnectivityManager) 
        getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); 
boolean isWifiConn = networkInfo.isConnected();
networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
boolean isMobileConn = networkInfo.isConnected();
Log.d(DEBUG_TAG, "Wifi connected: " + isWifiConn);
Log.d(DEBUG_TAG, "Mobile connected: " + isMobileConn);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM