Screen resolution set up Android

Hi, I’m making my first game for android… I would like to know how to set the screen resolution properly so my game can be played in any android device… a smartphone, or tablet… 4", 7", etc… right now I’ve only tested it on my 7" tablet… but don’t have a smartphone to test it

actually i had this issue during my Android supported Casual game Development .
there are things to do , mostly , it refers to the way you choose to solve it . there is not an exact Aspect ratio to set on , or something Automatically sets the default Resolution , on every android device for sure .

they way i thing would be the solution is to manipulate the aspect parameter from the camera ( Actually you default Camera ) . how to set it would be like this :

public Camera Cam1; // where you will set your default ( main ) camera

void Start()
{
Cam1.aspect = (Screen.currentResolution.width / Screen.currentResolution.height);
//so this would stretch the game scene in order to adjust it to the Device’s screen
}

there are actually other ways like using the Function " Screen.SetResolution() " so that you can define your own resolution . this is the way i didn’t try actually , but it answered as i heard .

SetResolution works great for that particular level, but what if I wanted it to be a global adjustment setting for the entire game?

Right now on my Android project I am setting the resolution in the Main Camera Script with:

Screen.SetResolution(1280, 720, true);

Then I use a GUI.Matrix to format GUI elements:

//any other script with GUI Components

//formats GUI stuff easily
public GUIStyle GUIStyleButton;

//any kind of texture to use in OnGUI()
public Texture2D inventoryTexture;

float native_width = 1280;
float native_height = 720;

float rx;
float ry;

//position for texture
vector2 buttonTexturePosition = New Vector2 (0,0); 

//size for texture
vector2 buttonTextureSize = New Vector2 (100,100);

void Start()
{
//sets up matrix to adjust to any screenheight based on your native camera height
rx = Screen.width/ native_width;
ry = Screen.height / native_height;

buttonTexturePosition.x = buttonTexturePosition.x *(Screen.width/native_width);
		
buttonTexturePosition.y = buttonTexturePosition.y *(Screen.height/native_height);

buttonTextureSize.x = buttonTextureSize.x * (Screen.width/native_width);

buttonTextureSize.y = buttonTextureSize.y * (Screen.height/native_height);


}

void OnGUI()
{
//set matrix locally if necessary
float rx = Screen.width/ native_width;
float ry = Screen.height / native_height;

		
GUI.matrix = Matrix4x4.TRS (new Vector3(0, 0, 0), Quaternion.identity, new Vector3 (rx, ry, 1));

if (GUI.Button (new Rect (buttonTexturePosition.x, buttonTexturePosition.y, buttonTextureSize.x, buttonTextureSize.y), inventoryTexture, GUIStyleButton))
{
//what button does this same thing can be used for GUI.Label without if condition
}
}

Not sure if there’s a better solution but I was dreading trying to format for all Android devices but this method seems to so far work perfectly for me with both the camera and GUI components.