Advertisement
virtuoso_o

java code

Jun 12th, 2023
1,317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1.  if (call.method.equals("getPlatformVersion")) {
  2. //      val picker= TimePicker = view.findViewById(R.id.picker);
  3.      try{
  4.        Context context = pluginBinding.getApplicationContext();
  5.        File aarFile = new File(context.getApplicationInfo().dataDir +"/Users/odunayoojomo/Desktop", "tappx-sdk-4.0.4.aar");
  6.        if (!aarFile.exists()) {
  7.          result.error("FILE_NOT_FOUND", "The .aar file does not exist.", null);
  8.          return;
  9.        }
  10.        // Load the .aar file dynamically
  11.        DexClassLoader classLoader = new DexClassLoader(aarFile.getAbsolutePath(), context.getCacheDir().getAbsolutePath(), null, context.getClassLoader());
  12.        Class<?> aarClass = classLoader.loadClass("com.tappx.sdk.android.Tappx"); // Replace with the actual class from the .aar file
  13.  
  14.        // Create an instance of the loaded class
  15.        Object instance = aarClass.newInstance();
  16.  
  17.  
  18.        // Invoke methods or access fields from the loaded class
  19.        // For example, assuming there is a method named "exampleMethod" in the class:
  20.        Method method = aarClass.getDeclaredMethod("getVersion");
  21.        Object returnValue = method.invoke(instance);
  22.        if (returnValue instanceof String) {
  23.          String resultString = (String) returnValue;
  24.          System.out.println(resultString);
  25.          result.success(resultString);
  26.        } else {
  27.          result.error("INVALID_RETURN_TYPE", "The invoked method did not return a String.", null);
  28.        }
  29.      }catch (Exception e) {
  30.        result.error("CONNECT_ERROR", "Failed to connect to the .aar file: " + e.getMessage(), null);
  31.      }
  32.  
  33.     } else {
  34.       result.notImplemented();
  35.     }
  36.   }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement