public void RequestPermissions() { AndroidRuntimePermissions.Permission[] results = new AndroidRuntimePermissions.Permission[permissions.Length]; for (int i = 0; i < permissions.Length; i++) { DebugLog($"Requesting access to {permissions[i]}"); results[i] = AndroidRuntimePermissions.RequestPermission(permissions[i]); } ArrayList deniedPermission = new ArrayList(); for (int i = 0; i < results.Length; i++) { if (results[i] != AndroidRuntimePermissions.Permission.Granted) { deniedPermission.Add(permissions[i]); } } if (deniedPermission.Count > 0) { ShowPermissionsNeededPanel(); } else { SwitchScene(); Log.debug("Permissions Granted"); } }
private string GetAuthorClicked(String strpermission) { string strResult = ""; try { AndroidRuntimePermissions.Permission result = AndroidRuntimePermissions.RequestPermission(strpermission); switch (result) { case AndroidRuntimePermissions.Permission.Denied: //永久拒绝询问 strResult = ("权限被拒绝且不再询问"); AndroidRuntimePermissions.OpenSettings(); // 打开本程序的设置界面 break; case AndroidRuntimePermissions.Permission.Granted: //允许 strResult = ("权限已开启"); break; case AndroidRuntimePermissions.Permission.ShouldAsk: //拒绝权限但不拒绝询问 strResult = ("权限被拒绝"); break; } } catch (Exception eee) { strResult = eee.Message; } return(strResult); }
/** * <summary>Unity callback that is invoked when the script is enabled (is only executed one time).</summary> * <see>https://docs.unity3d.com/ScriptReference/MonoBehaviour.Start.html</see> */ void Start() { // Request permission to use location/Bluetooth communication. #if PLATFORM_ANDROID if (!Permission.HasUserAuthorizedPermission(Permission.Microphone)) { AndroidRuntimePermissions.Permission result = AndroidRuntimePermissions.RequestPermission(Permission.CoarseLocation); if (result == AndroidRuntimePermissions.Permission.Granted) { // Ensures that the application only quits if permission was not granted. permissionGranted = true; } } #endif // Initialise interface text fields. Init(); // Define events. AddObservables(); // Link the callbacks to the DeviceController object. DeviceController.OnDataEvent += OnNewDataEvent; DeviceController.OnDeviceConnectionChange += OnDeviceConnection; DeviceController.OnNewDeviceFound += OnNewDeviceFound; }
//public void AddRecord(string bssid, string room, string lat, string lon) //{ // //ask for external write permission // AndroidRuntimePermissions.Permission result = AndroidRuntimePermissions.RequestPermission("android.permission.WRITE_EXTERNAL_STORAGE"); // //check if granted // if (result == AndroidRuntimePermissions.Permission.Granted) // { // try // { // using (StreamWriter file = new StreamWriter(Path, true)) // { // file.WriteLine(bssid + ", " + room + ", " + lat + ", " + lon); // } // } // catch (Exception ex) // { // throw new ApplicationException("This program did an oopsie :", ex); // } // } //} public void Auto() { AndroidRuntimePermissions.Permission result = AndroidRuntimePermissions.RequestPermission("android.permission.ACCESS_FINE_LOCATION"); if (result == AndroidRuntimePermissions.Permission.Granted) { StartCoroutine(StartProcess()); } else { Debug.Log("Permission state: " + result); } }
// Start is called before the first frame update void Start() { AndroidRuntimePermissions.Permission result = AndroidRuntimePermissions.RequestPermission("android.permission.ACCESS_FINE_LOCATION"); if (result == AndroidRuntimePermissions.Permission.Granted) { Debug.Log("We have permission to access external storage!"); } else { Debug.Log("Permission state: " + result); } }
public void OnClick() { if (Permission.HasUserAuthorizedPermission(Permission.Camera)) { SceneManager.LoadScene("PhotoScene"); } else { AndroidRuntimePermissions.Permission result = AndroidRuntimePermissions.RequestPermission("android.permission.CAMERA"); if (result == AndroidRuntimePermissions.Permission.Granted) { SceneManager.LoadScene("PhotoScene"); } } }
public void Start() { AndroidRuntimePermissions.Permission result = AndroidRuntimePermissions.RequestPermission("android.permission.ACCESS_FINE_LOCATION"); if (result == AndroidRuntimePermissions.Permission.Granted) { Debug.Log("We have permission to access GPS and Camera"); } else { Debug.Log("Permission state: " + result); } // Requesting WRITE_EXTERNAL_STORAGE and CAMERA permissions simultaneously //AndroidRuntimePermissions.Permission[] result = AndroidRuntimePermissions.RequestPermissions( "android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.CAMERA" ); //if( result[0] == AndroidRuntimePermissions.Permission.Granted && result[1] == AndroidRuntimePermissions.Permission.Granted ) // Debug.Log( "We have all the permissions!" ); //else // Debug.Log( "Some permission(s) are not granted..." ); }
//请求麦克风的权限 public void RequestPermission() { #if UNITY_ANDROID && !UNITY_EDITOR AndroidRuntimePermissions.Permission result = AndroidRuntimePermissions.RequestPermission("android.permission.RECORD_AUDIO"); if (result == AndroidRuntimePermissions.Permission.Granted) { resultText.text = "请求--麦克风权限被--允许"; } else if (result == AndroidRuntimePermissions.Permission.ShouldAsk) { resultText.text = "请求--麦克风权限被--未同意可询问"; } else if (result == AndroidRuntimePermissions.Permission.Denied) { resultText.text = "请求--麦克风权限被--被拒绝到设置里开启"; } #elif UNITY_IOS && !UNITY_EDITOR #else #endif }
public void VerifyPermission() { #if UNITY_EDITOR SceneLoader.instance.LoadARScene(); #endif #if UNITY_IOS && !UNITY_EDITOR iOSCameraPermission.VerifyPermission(gameObject.name, "SampleCallback"); #endif #if UNITY_ANDROID && !UNITY_EDITOR AndroidRuntimePermissions.Permission result = AndroidRuntimePermissions.CheckPermission("android.permission.CAMERA"); switch (result) { case AndroidRuntimePermissions.Permission.Denied: _supportCanvasController.ShowWarningPanel(); break; case AndroidRuntimePermissions.Permission.Granted: SceneLoader.instance.LoadARScene(); break; case AndroidRuntimePermissions.Permission.ShouldAsk: { result = AndroidRuntimePermissions.RequestPermission("android.permission.CAMERA"); if (result == AndroidRuntimePermissions.Permission.Granted) { SceneLoader.instance.LoadARScene(); } else { _supportCanvasController.ShowWarningPanel(); } break; } } // SaveManager.instance.SavePermissionRequest(); #endif }
/// <summary> /// Capures the picture from the camera and analyzes it /// </summary> public void CapturePicture() { Result result = _barcodeReader.Decode(_cam.GetPixels32(), _cam.width, _cam.height); if (result != null) { AndroidRuntimePermissions.Permission permission = AndroidRuntimePermissions.RequestPermission("android.permission.INTERNET"); if (permission == AndroidRuntimePermissions.Permission.Granted) { FirebaseManager.Instance.SetDatabaseReference(result.Text); } else { ToastManager.Instance.ShowToast("No Internet permission"); } } else { ToastManager.Instance.ShowToast("No QR code found"); } }
public void ClickLocation() { CurrentPage = 1; FirstPanel.SetActive(false); SecondPanel.SetActive(false); ThirdPanel.SetActive(false); FourthPanel.SetActive(false); FifthPanel.SetActive(false); OutputText.SetActive(false); Loading.SetActive(false); PreviousButton.SetActive(false); NextButton.SetActive(false); LocationClicked = true; SearchClicked = false; FirstPage = true; LastPage = false; OnlyPage = false; try { //Ask for Permission AndroidRuntimePermissions.Permission result = AndroidRuntimePermissions.RequestPermission("android.permission.ACCESS_FINE_LOCATION"); //If granted if (result == AndroidRuntimePermissions.Permission.Granted) { //Grab lat and long StartCoroutine(GetLocation()); } } catch (Exception) { Loading.SetActive(false); OutputText.SetActive(true); PageTextObj.SetActive(false); OutputTextResult.text = "Failed to determine location"; } }
private void Start() { Screen.orientation = ScreenOrientation.Portrait; _rawImage = GetComponent <RawImage>(); _barcodeReader = new BarcodeReader(); WebCamDevice[] devices = WebCamTexture.devices; if (devices.Length > 0) { int i = 0; while (i < devices.Length && devices[i].isFrontFacing) { i++; } if (i == devices.Length) { ToastManager.Instance.ShowToast("No camera found"); } else { AndroidRuntimePermissions.Permission permission = AndroidRuntimePermissions.RequestPermission("android.permission.CAMERA"); if (permission == AndroidRuntimePermissions.Permission.Granted) { _cam = new WebCamTexture(devices[i].name); _cam.Play(); _rawImage.texture = _cam; StartCoroutine(Loader()); } else { ToastManager.Instance.ShowToast("No camera permission"); } } } }
public void shareImage() { AndroidRuntimePermissions.Permission result = AndroidRuntimePermissions.RequestPermission("android.permission.WRITE_EXTERNAL_STORAGE"); if (result == AndroidRuntimePermissions.Permission.Granted) { Debug.Log("We have permission to access external storage!"); } else { Debug.Log("Permission state: " + result); } // Requesting WRITE_EXTERNAL_STORAGE and CAMERA permissions simultaneously //AndroidRuntimePermissions.Permission[] result = AndroidRuntimePermissions.RequestPermissions( "android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.CAMERA" ); //if( result[0] == AndroidRuntimePermissions.Permission.Granted && result[1] == AndroidRuntimePermissions.Permission.Granted ) // Debug.Log( "We have all the permissions!" ); //else // Debug.Log( "Some permission(s) are not granted..." ); if (!isProcessing) { StartCoroutine(ShareScreenshot()); } }
IEnumerator FinishGame() { finished = true; isRecord = false; List <string> recordAnnotation = new List <string>(); try { if (GetScore() > PlayerPrefs.GetInt("Score", 0)) { isRecord = true; PlayerPrefs.SetInt("Score", GetScore()); recordAnnotation.Add("Score: " + GetScore()); ActivateRecordScreen(); GooglePlayActions.ReportResult(GooglePlayActions.scoreLeaderboardId, GetScore()); } if (startTime - 3 > PlayerPrefs.GetInt("Time", 0)) { isRecord = true; PlayerPrefs.SetInt("Time", (int)(Time.timeSinceLevelLoad - 3)); recordAnnotation.Add("Time: " + minutes.ToString("00") + ":" + seconds.ToString("00")); ActivateRecordScreen(); GooglePlayActions.ReportResult(GooglePlayActions.timeLeaderboardId, (long)(Time.timeSinceLevelLoad - 3) * 1000); } if (_badBubblesBurst > PlayerPrefs.GetInt("BadBubblesCount", 0)) { isRecord = true; PlayerPrefs.SetInt("BadBubblesCount", _badBubblesBurst); recordAnnotation.Add("Bad bubbles: " + _badBubblesBurst); ActivateRecordScreen(); GooglePlayActions.ReportResult(GooglePlayActions.bubblesCountLeaderboardId, _badBubblesBurst); } // достижение за прохождение первой трассы if (!PlayerPrefs.HasKey("Score")) { GooglePlayActions.UnlockAchievement(GooglePlayActions.pioneerAchiev); PlayerPrefs.SetInt("PinkFrame", 1); } // достижение за скоростной слив игры if (startTime - 3 <= 19) { GooglePlayActions.UnlockAchievement(GooglePlayActions.destrudoAchiev); } // достижение за 3000 очков if (GetScore() >= 3000) { GooglePlayActions.UnlockAchievement(GooglePlayActions.longLiveAchiev); PlayerPrefs.SetInt("KingFrame", 1); } //достижения за позицию в лидерборде GooglePlayActions.GetLeaderboardRank(GooglePlayActions.scoreLeaderboardId); GooglePlayActions.GetLeaderboardRank(GooglePlayActions.timeLeaderboardId); GooglePlayActions.GetLeaderboardRank(GooglePlayActions.bubblesCountLeaderboardId); } catch (Exception e) { Debug.Log(e); } menuPanel.SetActive(true); backButtonIngame.SetActive(false); menuBackground.GetComponent <UIElement>().Show(false); menuPanel.GetComponent <UIElement>().Show(false); nextButton.SetActive(true); audioSource.volume = 0.1f; badCarmaAlert.GetComponent <Animator>().enabled = false; pauseButton.GetComponent <Button>().interactable = false; finishPanel.SetActive(true); buttonsPanel.SetActive(true); scoresText.text = GetScore().ToString(); goodBubblesText.text = _goodBubblesBurst.ToString(); badBubblesText.text = _badBubblesBurst.ToString(); finishTimeText.text = minutes.ToString("00") + ":" + seconds.ToString("00"); finishText.text = "the end"; if (!isRecord) { //bool showAds = (UnityEngine.Random.Range(1, 5) == 1) ? true : false; //if (showAds) //{ // RequestInterstitialAds(); // Utilities.UpdatePrefs("WatchAdsCounter", 1); //} Utilities.UpdatePrefs("IsRecord", 0); } else { this.ActivateRecordScreen(); Utilities.UpdatePrefs("IsRecord", 1); yield return(new WaitForSeconds(1f)); if (Permission.HasUserAuthorizedPermission(Permission.Camera)) { SceneManager.LoadScene("PhotoScene"); } else { AndroidRuntimePermissions.Permission result = AndroidRuntimePermissions.RequestPermission("android.permission.CAMERA"); if (result == AndroidRuntimePermissions.Permission.Granted) { SceneManager.LoadScene("PhotoScene"); } } } if (recordAnnotation.Count > 0) { PlayerPrefs.SetString("RecordAnnotation", String.Join("\n", recordAnnotation.ToArray())); } }