2011-11-29 85 views
0

有沒有辦法找到設備當前的配置,如屏幕尺寸和密度,區域設置,區域等...如何以編程方式查找設備配置?

我正在尋找的是在選擇合適的資源設備當前配置,但我希望能夠從我的服務器下載資源。

有沒有辦法?我知道密度我可以找到,其餘的呢?

回答

1
 Display d = getWindowManager().getDefaultDisplay(); 
       int h = d.getHeight(); 
       int w = d.getWidth(); 
    // This will give u screen width and height   


    LocationManager myLocationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE); 

    Location myLocation = null; 
    if(myLocation == null) // if Default Location is Null 
       { 
        myLocation = myLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
       } 
       if(myLocation!=null) 
       { 
        String myLatitude = Location.convert(myLocation.getLatitude(), Location.FORMAT_DEGREES); 

        String myLongitude = Location.convert(myLocation.getLongitude(), Location.FORMAT_DEGREES); 
       } 

// You have to add "android.permission.ACCESS_COARSE_LOCATION" and "android.permission.INTERNET" permissions 
+0

那不是我正在尋找的東西。我發現配置對象上的一些配置是通過getResources()。getConfiguration()獲得的,但由於某種原因,config.screenLayout不是其中的一個'SCREENLAYOUT_SIZE_LARGE/SCREENLAYOUT_SIZE_NORMAL/SCREENLAYOUT_SIZE_SMALL' – piojo

相關問題