SORU
30 Kasım 2010, Salı


Nasıl bir Android uçak modu algılayabilir?

Wi-Fi algılar aktif olarak bağlı benim uygulama kodu var. Bu kod eğer uçak modu etkin ise bir RuntimeException tetikler. Bu mod zaten ayrı bir hata iletisi görüntüler etmek istiyorum. Nasıl güvenilir eğer bir Android cihaz uçak modunda olup olmadığını tespit edebilir miyim?

CEVAP
11 HAZİRAN 2013, Salı


Alex'in cevabı SDK sürüm denetimi içerecek şekilde genişleterek

/**
 * Gets the state of Airplane Mode.
 * 
 * @param context
 * @return true if enabled.
 */
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static boolean isAirplaneModeOn(Context context) {        
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return Settings.System.getInt(context.getContentResolver(), 
                Settings.System.AIRPLANE_MODE_ON, 0) != 0;          
    } else {
        return Settings.Global.getInt(context.getContentResolver(), 
                Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
    }       
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • My name is Festis and I'm free

    My name is F

    2 EKİM 2011
  • Malwarebytes

    Malwarebytes

    22 Temmuz 2007
  • Press Start

    Press Start

    4 HAZİRAN 2006