New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unable to display in native resolution #870
Comments
My current workaround:
window.innerHeight and window.innerWidth has the native resolution. |
I have a web game that I'm trying to port to mobile using Cordova. This issue is causing my game to render at a lower resolution, and no workarounds thus far posted can fix the problem. The workaround used by @victorzzt does seem to work for rendering the display at the correct resolution, but the touch points are off, which in the case of my game, makes it unplayable. I hope we can have a fix for this soon! |
It doesnt seem that there will be a solution soon :( |
Older versions of https://developer.chrome.com/multidevice/webview/pixelperfect may help find a temporary workaround. It makes references to use the native APIs: I'm pretty sure cordova-android already uses I'm also wondering if this would be more appropriate as a third-party plugin instead of a core feature... |
cordova-android does not use setUseWideViewPort(). (version 8.* at least) That is why you have the https://www.npmjs.com/package/cordova-plugin-viewport which does exactly what you said : public class MainActivity extends CordovaActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// enable Cordova apps to be started in the background
Bundle extras = getIntent().getExtras();
if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
moveTaskToBack(true);
}
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
// THIS PART IS MODIFIED BY THE PLUGIN
WebView webView = (WebView) appView.getView();
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
}
} Once you've done that. You can use the meta viewport with some javascript to use the native resolution : let metaViewportElement = document.querySelector('meta[name="viewport"]');
if (metaViewportElement === null) {
metaViewportElement = document.createElement('meta');
metaViewportElement.setAttribute('name', 'viewport');
document.querySelector('head').appendChild(metaViewportElement);
}
const metaViewPortContent = `user-scalable=no, width=device-width, initial-scale=${1 / devicePixelRatio}, maximum-scale=1`;
metaViewportElement.setAttribute('content', metaViewPortContent); PS : the cordova-plugin-viewport is bugged. You need to modify it's plugin.xml to move the hook after_prepare outside of the platform cordova section BEFORE running cordova prepare. If it doesn't work, try deleting the plugins and platforms folders and rerun cordova prepare |
Thanks a lot for your hints! My first android-app (html,css,js,ajax,sse) already runs with cordova, due to the diplayed resolution (In mobile browser it fits perfect as a website). I downloaded viewport as a zip, copied all data into project folder, modified MainActivity,java by editor and built cordova without failures. Next I will implement your javascript into my application and build again.
|
WOW! 👍 :o) |
If you modify MainActivity,java yourself by hand, you can completely skip cordova-plugin-view => the only goal of the plugin is to modify the source code of MainActivity,java when you run cordova prepare. It does nothing else. The plugin does this by using the hooks after_prepare to execute a custom script after every cordova prepare command which override the MainActivity.java file.
Every cordova plugins comes with a plugin.xml file at its root. It describes stuff about the plugins. <?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-plugin-viewport" version="1.0.4" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>Viewport</name>
<engines>
<engine name="cordova" version=">=6.0.0" />
<engine name="cordova-android" version=">=5.0.0" />
</engines>
<platform name="android">
<hook type="after_prepare" src="set-viewport.js" /> <!-- Not supposed to be inside <platform name="android"/> -->
</platform>
</plugin>
cordova build = cordova prepare + cordova compile If you modify MainActivity.java by hand, you will likely loose you modifications every time you run cordova prepare (or any "higher" command). The content of plugins/ and platforms/ is entirely managed by cordova and we are not supposed to touch it. Cordova will likely override the content of platforms/ and your hand made MainActivity.java at some point. |
thanks for android cordova project which help building android app from web frontent. We have tried to fit the resolution of the frontend (reactjs) to the tablet resolution (1280x800) however even using your method ("cordova-plugin-viewport") in this issue, it doest not fit the tablet resolution. We are using :
Do you have any ideas/tests we can run in cordova to fit/force the resolution from the frontend to fit the hardware resolution ? Best. Xavier. |
Unfortunately, it's a tiny bit more complicated than simply adding the plugin right now. |
Closing as stale. |
On android it is impossible to display the cordova webview in native full resolution.
the webview is currently always using CSS Units so the rendering of the webview is divided by the pixel density of the devise, rendering the view in a very low resolution.
Scaling the view is not fixing this issues, neither forcing the user-agent to the "desktop-view" value.
We should have a way to force Cordova to render in "Desktop-View" in cordova Android or in native resolution.
#apache/cordova-lib#718
others experiencing the same issue:
@tscislo @brodybits @rokobuljan @getDOKI @basvanmeurs @jameelio @geniusq1981
Case is:
making a web app on android TV with cordova.
The TV device resolution is 1920x1080.
but when I run the app , the window.innerwidth/innerheight is 960x540 though it is fullscreen also.
While the html page is designed with 1920*1080 , so it was shown partly.
I find nothing useful about this from the cordova offical guideline.
The text was updated successfully, but these errors were encountered: