概要
using UnityEngine;
namespace Kogane
{
public static class AirplaneModeChecker
{
public static bool IsAirplaneMode
{
get
{
#if UNITY_EDITOR || UNITY_ANDROID
if ( Application.isEditor ) return false;
using var unityPlayer = new AndroidJavaClass( "com.unity3d.player.UnityPlayer" );
var currentActivity = unityPlayer.GetStatic<AndroidJavaObject>( "currentActivity" );
var settingsGlobal = new AndroidJavaClass( "android.provider.Settings$Global" );
var airplaneMode = settingsGlobal.CallStatic<int>( "getInt", currentActivity.Call<AndroidJavaObject>( "getContentResolver" ), "airplane_mode_on" );
return airplaneMode == 1;
#else
return false;
#endif
}
}
}
}
using Kogane;
using UnityEngine;
public class Example : MonoBehaviour
{
private void Update()
{
Debug.Log( AirplaneModeChecker.IsAirplaneMode );
}
}
参考サイト様