添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
I have a Xamarin.Android game, which I am trying to port to .NET6
I have a dependency on Xamarin.Android.Support.v4 - which provides functionality described below:

Android.Support.V4.View:

  • IOnApplyWindowInsetsListener
  • ViewCompat.SetOnApplyWindowInsetsListener
  • Android.Support.V4.Content:

  • ContextCompat.CheckSelfPermission
  • FileProvider.GetUriForFile
  • I want to continue targeting API 32 with minimal version set to API 19.
    What do I need to reference instead? Many thanks for any useful tips!

    Hello,

    For using those APIs you mentioned, you could refer to the following documentations:

    AndroidX.Core.View

  • OnApplyWindowInsetsListener
  • [ViewCompat.SetOnApplyWindowInsetsListener]( https://developer.android.google.cn/reference/androidx/core/view/ViewCompat#setOnApplyWindowInsetsListener(android.view.View,androidx.core.view.OnApplyWindowInsetsListener\) )
  • AndroidX.Core.Content:

  • [ContextCompat.CheckSelfPermission]( https://developer.android.google.cn/reference/kotlin/androidx/core/content/ContextCompat#checkSelfPermission(android.content.Context,java.lang.String\) )
  • [FileProvider.GetUriForFile]( https://developer.android.google.cn/reference/androidx/core/content/FileProvider#getUriForFile(android.content.Context,java.lang.String,java.io.File\) )
  • And here are the samples of using the APIs in Xamarin.Forms on Android platform:

    Implement IOnApplyWindowInsetsListener:

       public class RootViewDeferringInsetsCallback : WindowInsetsAnimationCompat.Callback, IOnApplyWindowInsetsListener  
           public RootViewDeferringInsetsCallback(int dispatchMode) : base(dispatchMode)  
           public WindowInsetsCompat OnApplyWindowInsets(View v, WindowInsetsCompat insets)  
           public override WindowInsetsCompat OnProgress(WindowInsetsCompat insets, IList<WindowInsetsAnimationCompat> runningAnimations)  
    

    ViewCompat.SetOnApplyWindowInsetsListener:

       RootViewDeferringInsetsCallback callback = new RootViewDeferringInsetsCallback(WindowInsetsAnimationCompat.Callback.DispatchModeStop);  
       ViewCompat.SetOnApplyWindowInsetsListener(your_view, callback);  
    

    ContextCompat.CheckSelfPermission:

       var selfPermission = ContextCompat.CheckSelfPermission(this, Manifest.Permission.Camera);  
       if (selfPermission == Permission.Granted)  
    

    FileProvider.GetUriForFile:

    At first, please refer to FileProvider to configure your FileProvider.
    Then, in you Xamarin project, you could use the following code to call FileProvider.GetUriForFile:

       File imagePath = new File(FilesDir, "my_images");  
       File newFile = new File(imagePath, "default_image.jpg");  
       Android.Net.Uri contentUri = FileProvider.GetUriForFile(this, "com.mydomain.fileprovider", newFile);  
    

    Best Regards,

    Alec Liu.

    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.