Ask help for Java to Xamarin C#

tabztabz Member
edited September 9 in Xamarin.Android

I really new for Xamarin, I need to transform below Java code to Xamarin by C#, and any help will be highly appreciated! Thank you!

DexFile df = new DexFile(apk);

ClassLoader classLoader = context.getClassLoader();

Class SystemProperties = Class.forName("android.os.SystemProperties");

SystemProperties.getMethod("set", new Class[]{String.class, String.class}).invoke(SystemProperties, new Object[]{new String("ctl.start"), new 
String("DiagDaemon")});

df.close();

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai
    edited September 9

    I converted it, you can refer to the following code. I Just convert the code, I did not test it function, you should test it for yourself.

           DexFile df = new DexFile(apk);
           ClassLoader classLoader = context.ClassLoader;
    
            Class SystemProperties = Class.ForName("android.os.SystemProperties");
    
            SystemProperties.GetMethod("set", new Class[] {  Java.Lang.Class.FromType(typeof(Java.Lang.String)),
                    Java.Lang.Class.FromType(typeof(Java.Lang.String))}).Invoke(SystemProperties, new Object[]{new String("ctl.start"), new String("DiagDaemon")});
    
             df.Close();
    

    You can refer to this link as well
    https://docs.microsoft.com/en-us/xamarin/android/get-started/java-developers#fundamentals

Sign In or Register to comment.