2017-10-09 40 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(); 
     } 
    } 
相關問題