相关疑难解决方法(0)

Android检查互联网连接

我想创建一个使用互联网的应用程序,我正在尝试创建一个检查连接是否可用的功能,如果不可用,请转到具有重试按钮和解释的活动.

附件是我的代码到目前为止,但我收到了错误 Syntax error, insert "}" to complete MethodBody.

现在我一直把这些放在试图让它工作,但到目前为止没有运气...任何帮助将不胜感激.

public class TheEvoStikLeagueActivity extends Activity {
    private final int SPLASH_DISPLAY_LENGHT = 3000;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        private boolean checkInternetConnection() {
            ConnectivityManager conMgr = (ConnectivityManager) getSystemService (Context.CONNECTIVITY_SERVICE);
            // ARE WE CONNECTED TO THE NET
            if (conMgr.getActiveNetworkInfo() != null
                    && conMgr.getActiveNetworkInfo().isAvailable()
                    && conMgr.getActiveNetworkInfo().isConnected()) {

                return true;

                /* New Handler to start the Menu-Activity
                 * and close this Splash-Screen after …
Run Code Online (Sandbox Code Playgroud)

networking android android-networking

204
推荐指数
11
解决办法
31万
查看次数

检查Android互联网连接的完美功能,包括蓝牙平台

我的应用程序在wifi和移动网络中工作得很完美,但无法检测何时通过蓝牙网络共享连接.

public boolean isNetworkAvailable() {
    ConnectivityManager cm = (ConnectivityManager) 
      getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();

    if (networkInfo != null && networkInfo.isConnected()) {
        return true;
    }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

我尝试运行其他一些应用程序.他们也没有显示网络连接,但谷歌应用程序工作得很好,所以像其他一些应用程序,如whatsap.想知道他们是如何做到的,以及为什么大多数应用程序都忽略了这一点.

任何人都可以告诉我一种方法来检查Android中的互联网连接,通过所有可用的方式,包括蓝牙泛和代理等.

任何帮助将不胜感激.提前致谢..

android android-bluetooth

14
推荐指数
2
解决办法
1677
查看次数