How to make my app look the same in all devices?
According to the official documentation, you don't need to programmatically decide which layout to use with the respective screen size.
To optimize your application's UI for the different screen sizes and
densities, you can provide alternative resources for any of the
generalized sizes and densities. Typically, you should provide
alternative layouts for some of the different screen sizes and
alternative bitmap images for different screen densities. At runtime,
the system uses the appropriate resources for your application, based
on the generalized size or density of the current device screen.
In other words, if you follow the recommendation stated in the documentation, as I can see that you've done, placing your layout files in their respective resource folder like so:
res/layout/main_activity.xml # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml # For 10” tablets (720dp wide and bigger)
Then the system will decide, which layout to use. No additional code is needed for you to specify it at run time.
If you however would want to make changes depending on your screen resolution, you could get the width and height in pixels using the following code
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
Then do something cleaver depending on the width
and height
variables, e.g. in your case with the S2:
if(width == 480 && height == 800){
//Do work that's related to the S2 screen resolution
}else if(...){
}
How to run android app in all connected devices or emulators at the same time from Android Studio?
Hold down SHIFT and click each device you want to run your app on when the device chooser is displayed.
This only works for running the app, if you choose to debug, this is limited to one device only
App not working in all devices
On Android >=6.0, We have to request permission runtime.
Step1: add in AndroidManifest.xml file
Step2: Request permission.
Step3: Handle callback when you request permission.
Check this one: Permission at Run Time
Edit: I think you have similar Issue:
Related Topics
Error Androidmanifest.Xml Doesn't Exist or Has Incorrect Root Tag
Prevent Screen Rotation on Android
Remove Items from Listview With a Custom Adapter
Alarm Manager Won't Work When the App Is Killed in the Background and Device Is Locked
How to Display Date Picker for Android With Only Month and Year Fields
How to Restrict Entry of Numbers But Allow All the Special Characters and Alphabets in Edittext
Retrieve Stored Image from Firebase Storage
Android Notification Has a Color Icon Instead of Being Turned White
Not Opening Specific Activity on Notification Click When the App Is in Background/Not Running
Ship an Application With a Database
How to Set Up Android Studio to Work Completely Offline
How to Make a Textview Automatically Scroll as I Add More Lines of Text
Remove Old Fragment from Fragment Manager
How to Figure Out Which Sim Received Sms in Dual Sim Android Device
How to Disable Spinner in Android and Enable It on Button Click
Android: How to Propagate Click Event to Linearlayout Childs and Change Their Drawable