Force Screen Resolution 480x320 on 3.2 (part 2)

Hi,

because of several reasons (performance among other reasons) I want a screen resolution of 480x320.
I set following properties in the AndroidManifest.xml like described in this thread.

        <supports-screens
        android:smallScreens="false"
        android:normalScreens="true"
        android:largeScreens="false"
        android:anyDensity="false"/>

With this settings I have a border on the right of my screen as expected (nexus one). In Unity 3.2 the main frame is rendered twice in vertical alignment within this border… that was not expected.
What I want is a black border left and right. I can achieve that when I add this line to my main activity:

getWindow().setLayout(480, 320);

Now it looks exactly like I want it. Unfortunately I get the titlebar as soon as I add that line and android:theme=“@android:style/Theme.NoTitleBar” takes no effect anymore.

I tried to hide the titlebar programmatically with no success.

Has anybody a solution for this issue or any ideas how it could be solved?

I figured out that if I add android:theme="@android:style/Theme.NoTitleBar.Fullscreen" to the androidmanifest.xml file the titlebar is hidden the first time and I have a window dimension of 480x320. That’s what I wanted to achieve.

Unfortunately it works only the first time I start the app. The titlebar is back again on the second launch (without compiling) - definitely the most stubborn titlebar I’ve ever seen.

Finally it’s solved. Adding these lines in onCreate fixes the issue.

@Override
protected void onCreate(Bundle savedInstanceState)
{
	Window window = getWindow(); 
	window.setGravity(Gravity.CENTER | Gravity.FILL_HORIZONTAL | Gravity.FILL_VERTICAL); 
	window.setLayout(480, 320); 
	window.requestFeature(Window.FEATURE_NO_TITLE); 
	window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
		
	super.onCreate(savedInstanceState);
}

I know that it is not a Unity issue but an Android issue. Anyhow I posted the issue because I can imagine that some Unity game developers want to set low res on Android to get some more performance.

@edit:
Hm, it’s not centered anymore.

I didn’t find a solution. Here is a crappy hack but the only way I get it to work.
I sent a bug report to Android.

/*
 * (non-Javadoc)
 * 
 * @see android.app.Activity#onStop()
 */
@Override
protected void onStop()
{
    super.onStop();


    //hack to prevent stopping fullscreen mode if the home button was pressed
    ActivityManager am = (ActivityManager) this
                    .getSystemService(ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
    ComponentName componentInfo = taskInfo.get(0).topActivity;

    if(componentInfo.getShortClassName().equalsIgnoreCase(".Launcher"))
    {
        onDestroy();
    }
}


@Override
public void onDestroy()
{
    super.onDestroy();
    System.runFinalizersOnExit(true);
    System.exit(0);
}

did you also try Screen.setResolution() call from Unity scripts?

Screen.setResolution() could do it but not in full screen, at least on my phone.

Yes, Screen.setResolution() took no effect unfortunately. It is an Android or Device bug anyway. I had several test cases with a non-unity project.

I have tried this on a nexus one and if you call Screen.setResolution() in a Start function it will force the back buffer resolution to what you set it to. The application will then display fullscreen in the desired resolution.

On my Galaxy S, everything is stretched even when I set the resolution to 320 x 480. So I set camera’s pixelRect width and height and it works pretty well for me.

function Start()
{
	if( Screen.currentResolution.height > 480 )
	{
		this.camera.pixelRect = Rect(0,
									 (Screen.currentResolution.height - Screen.currentResolution.width*1.5)*0.5,
									 Screen.currentResolution.width,
									 Screen.currentResolution.width*1.5);
	}
}

This will center the game screen with black borders on the top and the bottom.

do we can force the set the resolution for any phone resolution to our resolution? i have coded the menu gui controls for 320*480, if we set like yours,does it menu stretched automatically on higher resolution like xperia arc?