Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
public class DefaultPackageClass {
public void test() {
System.out.println(this.getClass().getName() + ": test");
}
public void testParams(String param1, String param2) {
System.out.println(this.getClass().getName() + ": " + param1 + " "
+ param2);
}
}
package de.tutorials;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class DefaultPackageWrapper {
private Object instance;
public DefaultPackageWrapper() {
try {
Class forName = Class.forName("DefaultPackageClass");
instance = forName.newInstance();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void test() {
callMethod("test");
}
public void testParams(String param1, String param2) {
callMethod("testParams", param1, param2);
}
private void callMethod(String name, Object... args) {
Class[] clazzes = new Class[args.length];
for (int i = 0; i < args.length; i++) {
clazzes[i] = args[i].getClass();
}
try {
Method method = instance.getClass().getMethod(name, clazzes);
method.invoke(instance, args);
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package de.tutorials;
public class Test {
public static void main(String[] args) throws Exception {
DefaultPackageWrapper wrapper = new DefaultPackageWrapper();
wrapper.test();
wrapper.testParams("Hallo", "Welt");
}
}
DefaultPackageClass: test
DefaultPackageClass: Hallo Welt