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

  • Baby Big Mouth

    Baby Big Mou

    5 Mart 2013
  • Bucky Roberts

    Bucky Robert

    9 HAZİRAN 2011
  • placeboing

    placeboing

    7 Mart 2006