Android cannot set screenOrientation, - android-activity

I have read through every post I could find on this and other sites and followed the advice, but in the most simple implementation I cannot get the Note 5 to set to Portrait mode when it is physically in Landscape orientation.
I added the lines as recommended to the manifest file, rebuilt and the app starts in Landscape mode.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.twistlogic.miwidget">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I also tried doing this with code, which is my main purpose:
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
nothing is produced that works.
I am trying to learn Android so I understand this may well be due to my limited knowledge. What I am trying to do is fix the orientation and lock it there, then allow it to change only when the user pushes a button. I did read that the screen size had to be set after API 13. But I am not certain how to do so. I am using a fragment template screen from the basic activities when the project was created.
Thanks for any help.

This can be set in the Main Activity I have not tried to set it in the Manifest here is a single line of code and a few lines to write a test Ok here is the Manifest code at the end
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
int orientation = getResources().getConfiguration().orientation;
if(orientation == Configuration.ORIENTATION_PORTRAIT){
}else if(orientation == Configuration.ORIENTATION_LANDSCAPE){}
In your manifest file after your main activity Paste below line.
android:screenOrientation="portrait"
I have not tested this code in a Manifest file

Related

requires your app to be migrated to the Android embedding v2. ......how to solve this problem? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
it keeps says me that
requires your app to be migrated to the Android embedding v2. Follow the steps on
https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects
Note....its the same as following this steps
https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects
but i made it easier for any one that cant follow the steps .....hope that helped.
After trying multiple ways to deal with the situation,
I ended up with a good enough solution
just open this files in your project and copy >> paste this lines of code and it will work .......make sure to delete all lines of code in your this files and replace it to this new ones.
1: MainActivity.java
package co.appbrewery.flash_chat;
import io.flutter.embedding.android.FlutterActivity;
public class MainActivity extends FlutterActivity {
}
2: styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="#android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">#drawable/launch_background</item>
</style>
</resources>
3: AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="co.appbrewery.flash_chat">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application android:label="flash_chat" android:icon="#mipmap/ic_launcher">
<activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="#style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in #style/LaunchTheme). -->
<meta-data android:name="io.flutter.embedding.android.SplashScreenDrawable" android:resource="#drawable/launch_background" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data android:name="flutterEmbedding" android:value="2" />
</application>
</manifest>
Follow the steps. Hopefully, your problem will be solved. https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects

I am getting so many errors in AndroidManifest.xml. How can I solve them?

Following is my code:
the errors I'm getting are:
Unresolved class 'FlutterApplication'
Attribute android:icon is not allowed here
Unresolved class 'MainActivity'
Attribute android:launchMode is not allowed here
Attribute android:theme is not allowed here
Attribute android:configChanges is not allowed here
Attribute android:hardwareAccelerated is not allowed here
Attribute android:windowSoftInputMode is not allowed here
<!-- The INTERNET permission is required for development. Specifically,
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="BMI Calculator"
android:icon="#mipmap/bmi_calculator">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in #style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

Alarm Activity gets launched on launching the app

Scenario : I have a simple to-do app where In the main activity I have a fragment that takes a list of to-dos from the user. I set an alarm for a fixed time in the future (in my case every 2 min ONLY for testing. The AlarmReceiver class launches an AlarmActivity which shows the list of to-dos as checkboxes for the user to mark as done.
When the alarm comes up and shows the list, I have a "Submit" button to mark all the checked items as 'done' in the local db.
Problem:
This AlarmActivity disappears on click of submit since I'm calling finish on it. But when I launch the app from the icon, the AlarmActivity is shown instead of the main activity.
AlarmReceiver code :
final Intent intent1 = new Intent(context, CheckListAlarmActivity.class);
intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_NO_HISTORY);
context.startActivity(intent1);
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:noHistory="true"
android:clearTaskOnLaunch="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AlarmActivity"
android:alwaysRetainTaskState="false"
android:clearTaskOnLaunch="true"
android:showOnLockScreen="true"
android:screenOrientation="sensorPortrait"
android:noHistory="true"/>
<receiver android:name=".AlarmReceiver" />
</application>
I added the android:clearTaskOnLaunch="true" and that seems to do the trick sometimes but not always.
And in the background when I put the loggers, it shows that every time I launch using the app icon it calls the onCreate of the MainActivity and then immediately calls the onCreate of the AlarmActivity.
I have tried looking for all kinds of solutions and tried setting a bunch of flags to the Intent. Nothing seems to do the trick convincingly.
It seems like a simple problem but I am not able to find the solution. Any help/guidance would be appreciated.

Moto 360 custom watch face lag

I'm developing watch faces for android wear devices. Everything was working well but we encountered problems on Moto 360. My users complain that quite big lag occures when user wants to activate the watch. Screen is shown after from 1 to 5 sec after touching the screen (sometimes it works faster, sometimes slower). Anyone had problem like that? My apps are tested on Samsung Gear Live and LG G Watch and works fine on them. I'm not able to get Moto right now.
You can check apps that I made here: https://play.google.com/store/apps/developer?id=Zuhanden
This is my manifest (maybe something is missing?):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="co.smartwatchface.watch.face.speedometer.android.wear"
android:versionCode="14"
android:versionName="1.9" >
<uses-sdk
android:minSdkVersion="20"
android:targetSdkVersion="20" />
<application
android:name="de.zuhanden.smartwatch.wear.squares.WatchApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="de.zuhanden.smartwatch.wear.squares.ui.activities.RectWatchfaceActivity"
android:allowEmbedded="true"
android:enabled="true"
android:label="#string/watchface_label_rect"
android:taskAffinity="" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.google.android.clockwork.home.category.HOME_BACKGROUND" />
</intent-filter>
<meta-data
android:name="com.google.android.clockwork.home.preview"
android:resource="#drawable/watchface_launcher_rect" />
</activity>
<activity
android:name="de.zuhanden.smartwatch.wear.squares.ui.activities.RoundWatchfaceActivity"
android:allowEmbedded="true"
android:enabled="true"
android:label="#string/watchface_label_round"
android:taskAffinity="" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.google.android.clockwork.home.category.HOME_BACKGROUND" />
</intent-filter>
<meta-data
android:name="com.google.android.clockwork.home.preview"
android:resource="#drawable/watchface_launcher_round" />
</activity>
<activity
android:name="de.zuhanden.smartwatch.wear.squares.ui.activities.SpeedometerActivity"
android:label="#string/app_name"
android:icon="#drawable/ic_launcher">
<intent-filter >
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="de.zuhanden.smartwatch.wear.squares.services.DataLayerListenerService" >
<intent-filter>
<action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
</intent-filter>
</service>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
Google play services are used in application, not in watchface, so it should not be a problem. I also use this method to check watch state and control animation fps:
#Override
public void onDisplayChanged(int displayId) {
final Display display = displayManager.getDisplay(displayId);
if (display != null) {
switch(display.getState()) {
case Display.STATE_DOZING:
onScreenDim();
break;
case Display.STATE_OFF:
onScreenOff();
break;
default:
// Not really sure what to so about Display.STATE_UNKNOWN, so
// we'll treat it as if the screen is normal.
onScreenAwake();
break;
}
}
}
When onScreenAwake() is called i switch to high fps (i call invalidate() repeatedly inside Handler) and inside onScreenOff() i stop handler and start refreshing screen only once per minute.
I would be grateful for any help.

How to fix screen orientation to portrait for my whole PhoneGap app

How to configure the Phonegap app to be fixed to only portrait mode, I there any possibility to do it with CSS or JavaScript so that I should be able to get the consistent behaviour across the platforms
I found this useful post detecting-displays-orientation-change-on-mobile-devices-with-accelerometer-a-platform-indipendent-approach
Here it is explained how to detect the orientation, but I need to configure it
Is it possible through CSS3 Media queries?
To fix your orientation in portrait mode just add the below line in your activity tag in AndroidManifest.xml file:
android:screenOrientation="portrait"
or this in the activity class:
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Actually you can use config.xml to set it to all devices if you're using PhoneGap Build...
Set the propertie: orientation with possible values default, landscape, or portrait
example:
< preference name="orientation" value="landscape" />
*please note that default means both landscape and portrait are enabled.
Source:
https://build.phonegap.com/docs/config-xml
use this code in your manifest
<activity android:name=".DroidGap"
android:label="#string/app_name"
android:screenOrientation="landscape" >
I had to update <path to phonegap app>/platform/android/AndroidManifest.xml with android:screenOrientation="portrait". Set to default, landscape, or portrait.
See below for a full example:
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="#string/app_name" android:name="HelloWorld" android:screenOrientation="portrait" android:theme="#android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>