2017-10-09 54 views
0

如果位置被禁用,我想显示框并停止执行过程,直到我打开位置并返回到我的应用程序。请提供必要的建议帮助。 功能, alertDialog.setTitle(“GPS Setting”); alertDialog.setMessage(“GPS未启用,是否要进入设置菜单?”);停止执行程序,直到在android中选择dialogalert选项

alertDialog.setPositiveButton("OK   ", new DialogInterface.OnClickListener() { 


     public void onClick(DialogInterface dialog, int which) { 
      Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); 
      mContext.startActivity(intent); 
     } 
    }); 

    alertDialog.setNegativeButton("Cancel           ", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int which) { 
      dialog.cancel(); 
      Toast.makeText(mContext, "Sorry we cannot proceed", Toast.LENGTH_SHORT).show(); 
     } 
    }); 

    alertDialog.show();// Showing Alert Message 
+0

我觉得这可能有助于您的问题https://stackoverflow.com/a/10311891/5693082 – Jerrol

回答

0

您应该使用ProgressDialog在https://developer.android.com/reference/android/app/ProgressDialog.html 看看这个例子:

private ProgressDialog progressDialog; 

    public void cerrarSession() { 
     try { 
      showDialog(); 
      // do something 
     } catch (InternetException e) { 
      // some exception 
      e.printStackTrace(); 
     } 
    } 

    private void showDialog() { 
     progressDialog = new ProgressDialog(SavingsRequestsManager.getActivity()); 
     progressDialog.setCancelable(false); 
     closeDialog(); 
     progressDialog.setMessage(SavingsRequestsManager.getActivity().getString(R.string.progress)); 
     progressDialog.show(); 
    } 

    public void closeDialog() { 
     if (progressDialog != null && progressDialog.isShowing()) { 
      progressDialog.dismiss(); 
     } 
    } 
相关问题