【问题标题】:Unknown Issue using Samsung phones使用三星手机的未知问题
【发布时间】:2014-03-06 06:21:19
【问题描述】:

我在 android 中开发了一个应用程序。该应用程序由通过 Web 服务进行的服务器和客户端交互组成。我检查了 wifi 连接状态,如果连接状态为假,我已显示注意框,如果连接状态为真,我将执行一些操作。但我遇到的问题是注意框显示在 LG、Sony 和其他智能手机上,除了 SAMSUNG 所有型号,包括 Galaxy S4。

谁能知道这件事......

我将在下面发布检查 wifi、4g 和状态的代码。

boolean connected = false;
     ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
     if(connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED || 
             connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED||
             connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIMAX).getState() == NetworkInfo.State.CONNECTED)
        {
     // some action
            //we are connected to a network
            connected = true;
        }
    if(connected == false){
    //      System.out.println("The Network error");
            attentionBox("There is no network connection right now. Please try again later.","Internet Connection Error"); 
        } 

注意框编码是:

 public void attentionBox(final String msg, final String title)
    {
        AlertDialog.Builder builder = new AlertDialog.Builder(ViewYourPlanList.this);
        builder.setMessage(msg)
                .setTitle(title)
                .setPositiveButton("OK", new android.content.DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        ((AlertDialog)dialog).getButton(which).setVisibility(View.INVISIBLE);
                         //finish();  
                         System.exit(0);
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    }

【问题讨论】:

  • 可以分享一下attentionBox编码吗
  • 我分享了彼得。它适用于除三星以外的所有其他手机????

标签: android performance web-services android-wifi galaxy


【解决方案1】:

这样试试

    public boolean isConnectingToInternet() {
       ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null)
            for (int i = 0; i < info.length; i++)
                if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }

    }
    return false;
}

【讨论】:

  • 我尝试了您发布的上述编码,但由于某种原因不支持 4G,因此我改变了我的逻辑
【解决方案2】:

试试这个,它对我有用

public void showAlertDialog(Context context, String title, String message) {
    AlertDialog alertDialog = new AlertDialog.Builder(context).create();

    // Setting Dialog Title
    alertDialog.setTitle(title);

    // Setting Dialog Message
    alertDialog.setMessage(message);


    // Setting OK Button
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
        }
    });

    // Showing Alert Message
    alertDialog.show();
}

如果它对你有用。投票给我。

【讨论】:

  • 我可以知道我在 alertDialog 中的编码有什么问题......我问这个,因为我想知道错误???正如你所说,我会尝试你的代码......我会在所有平台上进行测试
  • 你能分享你的日志猫吗
  • 伙计它不工作......首先我在真实设备上测试而不是在模拟器上......当我在模拟器中运行应用程序时没有错误......代码工作正常并且注意框显示在所有设备上....我检查了我的朋友手机...但问题是当我在 SAMSUNG 设备(Galaxy S4、Samsung icore 8262 等...)中运行我的应用程序时应用程序崩溃
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-04
相关资源
最近更新 更多