Adb am命令工作,但java代码中的意图不起作用

时间:2014-06-10 23:53:37

标签: java android android-intent adb

对不起我的英语,需要一些帮助

即时加载应用,此应用需要将ovpn文件导入openvpn连接应用。

我从adb运行此命令并正常工作

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

但是如果我正在构建一个启动相同命令的意图

    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);

启动后,openvpn应用程序打开但不导入配置文件。

意图是错的?

2 个答案:

答案 0 :(得分:0)

        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);

答案 1 :(得分:0)

Ionic Frameworkstartapp plugin一起使用即可:

navigator.startApp.start([
  ["net.openvpn.openvpn","net.openvpn.openvpn.OpenVPNAttachmentReceiver"],
  ["cdvfile://localhost/persistent/Download/asdf.ovpn"]
], function(message) {
  /* success */
}, 
function(error) {
  /* error */
});