question

XamarinInn-3565 avatar image
0 Votes"
XamarinInn-3565 asked LeonLu-MSFT commented

how to implement Lock Task Mode in xamarin application

My client want to use my application in a android Mobile Tab device.
client just want to keep it as a single app device.
This tab will be placed in a hospital and patients are allowed to use my app.
So we should not allow the user to minimise the app or we should not allow the user to exit from the application.

The existing app is a normal application that is already used in android and ios devices.

What we can do for that ?

https://docs.microsoft.com/fr-fr/dotnet/api/android.app.activity.startlocktask?view=xamarin-android-sdk-12&viewFallbackFrom=xamarin-android-sdk-9

I have seen a startlockTask concept from the above link,but i couldnt understand how to use it in my app.

Please help me with your seggestions.

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

LeonLu-MSFT avatar image
0 Votes"
LeonLu-MSFT answered LeonLu-MSFT commented

Hello,​


If you want to use startlockTask like this thread: https://docs.microsoft.com/fr-fr/dotnet/api/android.app.activity.startlocktask?view=xamarin-android-sdk-12&viewFallbackFrom=xamarin-android-sdk-9

Just add StartLockTask(); method in the OnCreate method of MainActivity.cs.

Best Regards,

Leon Lu



If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@XamarinInn-3565 May I know if you have got any chance to check my answer? I am glad to help if you have any other questions

0 Votes 0 ·

Hi Leon,

Thankks for your valuable time.
I have tried the same in may mainactivity file ,but getting the following error Error XA4203: The Name property must be a fully qualified 'package.TypeName' value, and no package was found for 'startLockTask'. (XA4203) .


my code-

namespace DebuggTestApp2.Droid
{
[Android.Runtime.Register("startLockTask", "()V", "GetStartLockTaskHandler")]
[Activity(Label = "DebuggTestApp2", 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
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);

         Xamarin.Essentials.Platform.Init(this, savedInstanceState);
         global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
         StartLockTask();
         LoadApplication(new App());
     }
     public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
     {
         Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

         base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
     }
 }

}




0 Votes 0 ·

This issue is related to [Android.Runtime.Register("startLockTask", "()V", "GetStartLockTaskHandler")] Why do you add this line? Can you remove it, then make a test.

0 Votes 0 ·

You can use StartLockTask() directly without any Registers

0 Votes 0 ·

@XamarinInn-3565 Did you remove [Android.Runtime.Register("startLockTask", "()V", "GetStartLockTaskHandler")] above MainActivity, Is that worked?

0 Votes 0 ·