Discussion:
display.getRealMetrics returns different results each time but works correctly if I change the manifest package name!!??
Chanon Sajjamanochai
2016-06-26 18:08:13 UTC
Permalink
Hello, I am at a dead end here and don't know what else I can do.

I've created a simple NativeActivity application that does:


public class MainNativeActivity extends NativeActivity {
@Override
protected void onStart() {
super.onStart();

Point size = new Point();
//Display display = getWindowManager().getDefaultDisplay();
Display display = ((WindowManager)
this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
display.getSize(size);
Log.d(TAG, "GET XXXXXXXXXXXXXXXXXX size is " + size.x + " " + size.y);


DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
Log.d(TAG, "GET XXXXXXXXXXXX2 metrics size is " + metrics.widthPixels + " "
+ metrics.heightPixels + " density " + metrics.density + " scaled density "
+ metrics.scaledDensity);

display.getRealSize(size);
Log.d(TAG, "GET XXXXXXXXXXXXXXXXXX real size is " + size.x + " " + size.y);

DisplayMetrics metrics1 = new DisplayMetrics();
display.getRealMetrics(metrics1);
Log.d(TAG, "GET XXXXXXXXXXXX2 REAL metrics size is " +
metrics1.widthPixels + " " + metrics1.heightPixels + " density " +
metrics1.density + " scaled density " + metrics1.scaledDensity);
}

There is no native code running just an empty ANativeActivity_onCreate (I
commented everything out to determine what is causing the problem).

If I use package name com.mycompany.mypreviouspublishedapp in the manifest
and gradle files, then the result is it returns the wrong resolution most
of the time. Sometimes it gets the right resolution. Basically for a Galaxy
S6 that has a resolution of 1440 x 2560 it returns 1080 x 1920 most of the
time.

For a Galaxy Tab S2 that has a resolution of 1536 x 2048 it returns 1152 x
1536 most of the time and 1024 x 768 sometimes.

I tried to figure out what I was doing wrong, so I tried starting with a
barebones project with a random package name and saw that it was working
correctly. Then I tried changing my original project one part a time
commenting out things and making it the same as the barebones project.
Until finally the only thing different was the package name. And so I tried
changing that and IT WORKED .. on the S6 it showed 1440 x 2560 every time.

Then in the barebones project I tried changing the package name to
com.mycompany.mypreviouspublishedapp and it starts giving different results
again.

Now, I can't fix it by publishing with a new package name (even if I'd go
with that an absurd solution) because I'm trying to release an update to an
existing published app.

The app/game was previously published with Google Play Games services, so I
don't know if it is related to that.

Anyways... if anyone has any ideas it would be greatly appreciated.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/4302543a-bf16-406e-9336-207a10150fea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
J Decker
2016-06-27 02:52:42 UTC
Permalink
try including targeting higher android platform levels... I found that if I
targeted too old I'd get a 'fake' surface... since the native window is
really a OpenGL surface, it just stretches the one it tells you (and yields
non pixel perfect results)
Post by Chanon Sajjamanochai
Hello, I am at a dead end here and don't know what else I can do.
public class MainNativeActivity extends NativeActivity {
@Override
protected void onStart() {
super.onStart();
Point size = new Point();
//Display display = getWindowManager().getDefaultDisplay();
Display display = ((WindowManager)
this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
display.getSize(size);
Log.d(TAG, "GET XXXXXXXXXXXXXXXXXX size is " + size.x + " " + size.y);
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
Log.d(TAG, "GET XXXXXXXXXXXX2 metrics size is " + metrics.widthPixels + "
" + metrics.heightPixels + " density " + metrics.density + " scaled density
" + metrics.scaledDensity);
display.getRealSize(size);
Log.d(TAG, "GET XXXXXXXXXXXXXXXXXX real size is " + size.x + " " + size.y);
DisplayMetrics metrics1 = new DisplayMetrics();
display.getRealMetrics(metrics1);
Log.d(TAG, "GET XXXXXXXXXXXX2 REAL metrics size is " +
metrics1.widthPixels + " " + metrics1.heightPixels + " density " +
metrics1.density + " scaled density " + metrics1.scaledDensity);
}
There is no native code running just an empty ANativeActivity_onCreate (I
commented everything out to determine what is causing the problem).
If I use package name com.mycompany.mypreviouspublishedapp in the manifest
and gradle files, then the result is it returns the wrong resolution most
of the time. Sometimes it gets the right resolution. Basically for a Galaxy
S6 that has a resolution of 1440 x 2560 it returns 1080 x 1920 most of
the time.
For a Galaxy Tab S2 that has a resolution of 1536 x 2048 it returns 1152
x 1536 most of the time and 1024 x 768 sometimes.
I tried to figure out what I was doing wrong, so I tried starting with a
barebones project with a random package name and saw that it was working
correctly. Then I tried changing my original project one part a time
commenting out things and making it the same as the barebones project.
Until finally the only thing different was the package name. And so I tried
changing that and IT WORKED .. on the S6 it showed 1440 x 2560 every time.
Then in the barebones project I tried changing the package name to
com.mycompany.mypreviouspublishedapp and it starts giving different results
again.
Now, I can't fix it by publishing with a new package name (even if I'd go
with that an absurd solution) because I'm trying to release an update to an
existing published app.
The app/game was previously published with Google Play Games services, so
I don't know if it is related to that.
Anyways... if anyone has any ideas it would be greatly appreciated.
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/4302543a-bf16-406e-9336-207a10150fea%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/4302543a-bf16-406e-9336-207a10150fea%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CAA2GJqUQ52FrEcBKaPW4SMc4o%3Dz-Hd0kT%2BHb%3DTjZ%2BF18L_Lf4w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Chanon Sajjamanochai
2016-06-27 04:51:09 UTC
Permalink
One thing I notice is that, if I uninstall the app before
running/reinstalling it through Android Studio it gives the correct
resolution the first time. Then if I close the app and open it again it
will return a smaller resolution and will keep doing that every time
afterwards.

However if I change the manifest package name, it will return the correct
resolution always.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/4f5b186a-d740-46e7-aa3e-efd233674a79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Chanon Sajjamanochai
2016-06-27 04:46:51 UTC
Permalink
Hi J Decker,

Thank you for the suggestion. I saw your previous post about a similar
issue, but I've done that, even increasing the minSdkVersion to 21 and it
still has the same behavior.

This is driving me a bit crazy.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/06fbf7fe-0b12-4ba4-9502-437c93426a5c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Adventures on the Road
2018-07-24 18:44:32 UTC
Permalink
This exact problem plagued me as well.

My project has a number of flavors and due to that the build time had slowed as the complexities increased. In the pursuit of a speedier build I had added the line - org.gradle.configureondemand=true to gradle.properties
Removing that seemed to have solved my problem.

I did also recently File | Invalidate Caches/Restart and unchecked File | Settings | Build Execution Deployment |Instant Run

But I believe the removing configureondemand=true was the solution to my problem.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/7c684fd7-f80d-4456-9797-520c578de476%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Adventures on the Road
2018-07-25 20:43:16 UTC
Permalink
Well, I thought that I had solved it as I stated in my previous reply but after a day of testing on multiple devices, I have come back to the same issue again.

On my Samsung S6, the first run, and sometimes subsequent runs, the display metrics show 1440 x 2560 but then on some future run reverts to always showing 1080 x 1920. I have not changed my display in anyway. The screenDensity also drops to show a lower number but again I have made no display changes.

If I uninstall the application and reinstall, again it runs for the first time giving the correct metrics.

I do have multiple flavors in this project but nothing about the flavors changes the display but other flavors which have different package names, as was stated in the initial question here, seem to work fine.

This is the most perplexing development issue that I have ever come across.

Is it potentially the Android Studio IDE making a mistake in the build due to multiple flavors? Perhaps it is actually the Android OS returning incorrect metrics.

I am eager to solve this issue as I have an update to publish which requires correct metrics values.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/471fbf87-5a5b-4e16-aff0-13f37599b5f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...