How to Make My App Work in All Devices

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



Leave a reply



Submit