If you just need a simple VpnService that blocks application traffic, without needing the extra feature of handling the packet tcp/udp headers that LocalVPN offers, you can just use ToyVPN (https://android.googlesource.com/platform/development/+/master/samples/ToyVpn) and use builder.addAllowedApplication or builder.addDisallowedApplication.
ToyVpnConnection.java:
for (String packageName : mPackages) {
try {
if (mAllow) {
builder.addAllowedApplication(packageName);
} else {
builder.addDisallowedApplication(packageName);
}
} catch (PackageManager.NameNotFoundException e){
Log.w(getTag(), "Package not available: " + packageName, e);
}
}
However, if you need low level access to the packets like with LocalVPN, then I am unsure how to do this. If you find out, please post any tips on accomplishing this as I am currently trying to figure this out myself!