Hello there I have an app which is compatible with Phone/Tablet and my TV Android Box .
However this app is not compatible with my Android Smart TV itself , like when i go to google play (which is Alpha) i get the text saying that the app is not compatible with the device.
I did some checks and I found that the app's menifest should mention that this is a LEANBACK_LAUNCHER, which I did like the following code:
[Activity(Label = "Afaq.IPTV", Icon = "#drawable/icon", MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[IntentFilter(new[] {"android.intent.action.MAIN"}, AutoVerify = true,
Categories = new[] {"android.intent.category.LEANBACK_LAUNCHER"})]
public class MainActivity : FormsApplicationActivity
{...
So am I missing something ? has anyone succeeded with this before ?
I found the solution
In the mainActivity you start the class the way I did in the Quesiton
[Activity(Label = "Afaq.IPTV", Icon = "#drawable/icon", MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[IntentFilter(new[] { Intent.ActionMain }, Categories = new[] {Intent.CategoryLauncher,Intent.CategoryLeanbackLauncher})]
public class MainActivity : FormsApplicationActivity
{...
In the manifest you have to add the following
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
After adding this line you will have an app that is available on Google Play store from your TV. However, if you have only this in the manifest then your app is not compatible with your touch screen devices (e.g. phones and tablets). Google this problem and you might find something useful which would solve this problem. My guess is by having another Activity that is for phones .
Related
Im developing an application using Xamarin forms for my android and iOS application. Currently when the application is being launched , a white screen is shown before my SplashScreen. How can we remove the white screen and shows directly the splash screen ?
App.xaml.cs
MainPage = new NavigationPage(new SplashScreen());
MainActivity.cs
{
[Activity(Label = "testApp", Icon = "#mipmap/icon", Theme = "#style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity, ActivityCompat.IOnRequestPermissionsResultCallback
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.SetTheme(Resource.Style.MainTheme);
base.OnCreate(savedInstanceState);
}
}
Android 12 doesn't allow an additional activity to act as a splash screen, so the link above is way out of date. The solution at the following link will enable a splash screen for any Xamarin.Android app. https://github.com/gmck/XamarinBasicSplashScreen.
The following is a link to the official android docs https://developer.android.com/develop/ui/views/launch/splash-screen
I just installed Rg.Plugins.Popup into my application and in the wiki example I see that it has:
"ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)"
[Activity(Label = "X", MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
My current Activity is this:
[Activity(Label = "X", Theme = "#style/MainTheme", MainLauncher = false)]
For an XF app is it important to have the additional entry for ConfigurationChanges in the activity?
If you remove it and you rotate the device, it will probably re-create the activity, meaning your App will appear to restart on rotation. Hence it is a good idea to keep those configuration change flags.
There are other flags you can use as well for resizing of activities when the software keyboard appears on screen as well. You can read more about handling configuration changes on Android in their documentation.
I have an application that looks good in portrait mode but doesn't look good in landscape mode.
Is there any way within forms or through custom renderers that I can set the application so that it always sets itself into portrait mode?
Not sure if this helps, but I am using Xamarin Essentials, just in case there's a way to do it with the functionality that Essentials offers.
Device screen orientation in xamarin is usually configured from Host(Android/iOS) project.
On iOS, device orientation is configured for applications using the Info.plist file.
On Android, open MainActivity.cs and set the orientation using the attribute decorating the MainActivity class:
namespace MyRotatingApp.Droid
{
[Activity (Label = "MyRotatingApp.Droid", Icon = "#drawable/icon", Theme = "#style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Landscape)] //This is what controls orientation
public class MainActivity : FormsAppCompatActivity
{
}
}
For more info, you can check this link
Look for this one in android
Activity(ScreenOrientation = ScreenOrientation.Portrait
In android MainActivity:
namespace Namespace.Droid
{
[Activity(ScreenOrientation = ScreenOrientation.Portrait , ...]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
...
In Ios Info.pList:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
make sure that only the portrait orientation remains
I've followed this post https://forums.xamarin.com/discussion/87795/onoptionsitemselected-not-invoked-using-masterdetails-page-on-android to get my back button event working. It works as expected until I change the orientation of the application. Is there a way to remedy this? Thanks.
As per me you just need to stop the changes that happen onConfigurationChange which can be done something like this;
For API > 13
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation
For API < 13
ConfigurationChanges = ConfigChanges.Orientation
For Eg:
[Activity(ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,...)
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
I am trying to change the color of a toolbar in a Xamarin.Forms application. I used this to change the color:
MainPage = new NavigationPage(new StartPage())
{
BarBackgroundColor = Color.FromHex("#15315A"),
BarTextColor = Color.FromHex("#F3F9F5")
};
This works successfully on iOS, but on Android the Toolbar is just white. I tried to change the styles colors, and defined a Toolbar.axml with no luck either. I posted the pictures below of what I am seeing. Anyone know what I could be doing wrong?
There was a fairly good answer on this post on the xamarin developer forums. Basically there's a couple of options to get this to work, these are:
An Appearance which works globally.
Or using a custom renderer.
[assembly: ExportRenderer(typeof(TabbedPage), typeof(TabbedPageCustom))]
namespace MobileCRM.iOS
{
public class TabbedPageCustom : TabbedRenderer
{
public TabbedPageCustom ()
{
TabBar.TintColor = MonoTouch.UIKit.UIColor.Black;
TabBar.BarTintColor = MonoTouch.UIKit.UIColor.Blue;
TabBar.BackgroundColor = MonoTouch.UIKit.UIColor.Green;
}
}
}