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

  • POGProductionz

    POGProductio

    27 NİSAN 2012
  • Randall P Studios

    Randall P St

    27 AĞUSTOS 2009
  • xCraash

    xCraash

    6 Temmuz 2012