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

  • BMG Rentals Property Management

    BMG Rentals

    23 Mayıs 2011
  • GamingAndTech

    GamingAndTec

    16 NİSAN 2013
  • Sergio Fernandez

    Sergio Ferna

    1 EKİM 2009