Search code examples
javaandroidandroid-intentadb

Adb am command work, but the intent in java code dont work


sorry for my english, and need a little help

im bulding an app, and this app need to import a ovpn file to the openvpn connect app.

im run this command from adb and work fine

    adb shell am start -n net.openvpn.openvpn/.OpenVPNAttachmentReceiver -a         android.intent.action.VIEW -d "/MyPcHardDis/profile.ovpn" -t "application/x-openvpn-profile"

but if im building an intent to launch the same command

    Intent intent = new Intent();
    intent.setAction("android.intent.action.VIEW");
    intent.setComponent(new   ComponentName("net.openvpn.openvpn","net.openvpn.openvpn.OpenVPNAttachmentReceiver"));
    intent.setData(Uri.parse("/storage/emulated/0/Download/asdf.ovpn"));
    intent.setType("application/x-openvpn-profile");
    startActivity(intent);

after launch, the openvpn app open but doesnt import the profile.

the intent is wrong?


Solution

  •         Intent intent = new Intent();
            intent.setAction("android.intent.action.VIEW");
            intent.setComponent(new ComponentName("net.openvpn.openvpn","net.openvpn.openvpn.OpenVPNAttachmentReceiver"));
            intent.setDataAndType(Uri.parse(file_path), "application/x-openvpn-profile");
            startActivity(intent);