How to determine if a launch rocket supports rotation of the main screen

This can be considered a repetition of this message , but he did not get the right answer, so perhaps the question needs a little more context to attract the answer.

Basically, I was able to configure the Monitoring Service , which monitors the rotation on the main screen, and when this happens, my AppWidgets updated in response.

Although this works as well as possible, the big mistake with this method is that it actually only detects the screen , not just the main screen . p>

Thus, typically, the device will support screen rotation in normal applications (i.e., Activity rotation). The problem is that rotating the screen under these circumstances falsely triggers my monitoring of the Service .

My widgets then think that they need to display and show new content for the rotated view, but if the home screen itself does not support rotation on the main screen, then this work is not only wasted, but also contributes to a poor interface.

So, is there a way to check if the launcher supports rotation on the main screen? Or, alternatively, a method for detecting rotation of the main screen , not just screen rotation (for example, in the application)?

I could just create a parameter to enable this rotation function or not, with the default turned off, but in fact I would like the function to turn on by default ... otherwise users with rotating home screens will consider my widgets They donโ€™t respond well to rotation without wasting time looking for options to enable the function for their device.

+7
android homescreen android-launcher
source share
5 answers

The Home (or launch) screen is very specific, and there are no specific ways in which you can express the orientation of each of them. Damn, you might have a diagonal screen!

Since there are so many implementations of the launch screen, the behavior on any given device will be undefined.

However:. You can easily add a flag of some type at the first start, which asks the user if their home screen supports orientation shifts. It would be very easy to add and would not put too much trouble on the user! :)

Edit:. If you want to determine what activity has changed orientation, you can simply get a list of all running applications with getRunningAppProcesses , and then check each result element of importance for IMPORTANCE_FOREGROUND . This way, you will find out if the user has changed orientation while the running application is in the foreground, and can check if this application or the home screen named onConfigurationChanged !

+1
source share

This answer will bother you. But in fact, you cannot know for sure that one launcher is supported by rotation or not, or is detected when the launcher is rotated.

Launcher is a regular Android application. And to meet your requirements, they must:

  • Public data through the Content Provider : You know that it supports rotation or not. What can they do, etc. And they have a well-known document.
  • send an event when they are rotated through BroastCastReceiver to listen to this event.

Often they are not .

+1
source share
 boolean autoRotateOn = (android.provider.Settings.System.getInt(getContentResolver(),Settings.System.ACCELEROMETER_ROTATION, 0) == 1) ; 
0
source share

Now, although there is no concrete way to detect a change in screen orientation on the main screen, I would blindly approach this problem, finding that the application is in the foreground during the onConfigurationChanged event.

How to determine if a front-end application is a launcher?

The method in the above message retrieves the package name for the foreground application and compares it with those launch applications that are installed on the device.

0
source share

You better know if the system is a pill. Here are my findings:

Test devices that can rotate their launcher:

 Samsung Galaxy Note 2 -- No Galaxy S4 -- No Galaxy S5 with Nova Launcher -- No Galaxy S6 -- No HTC One M7 Sense Launcher -- No Kyocera Hydro ICS Launcher -- No Galaxy Reverb, Galaxy Centura -- No Galaxy Note 4 TW -- No LG G3 -- No LG G2 -- No Tablets: Dell Venue 8 -- Yes, Stock Launcher Verizon Ellipsis -- Yes HP Slate -- Yes Galaxy Tab 3 - Yes Lenovo Tab - Yes Acer Iconia Tab -- Yes 

To detect a tablet, you can use this code:

 DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int width=dm.widthPixels; int height=dm.heightPixels; int dens=dm.densityDpi; double wi=(double)width/(double)dens; double hi=(double)height/(double)dens; double x = Math.pow(wi,2); double y = Math.pow(hi,2); double screenInches = Math.sqrt(x+y); 

double screenInches can be used against a number, such as 7 inches, to generally detect that the launcher can be rotated.

I donโ€™t think this is a workaround, itโ€™s honest how I would do it if I were developing an application.

Hope this helps!

0
source share

All Articles