【问题标题】:Bluetooth File transfer on Android(even restricted types)Android上的蓝牙文件传输(甚至限制类型)
【发布时间】:2013-04-23 01:22:12
【问题描述】:

我正在制作一个应用程序,我想在其中添加一项功能以通过蓝牙发送 apk 文件。它不允许通过传统方法,因为 apk 是受限制的文件类型,所以我使用了 BluetoothShare.java。显然它不适用于Jellybean。我得到一个令人讨厌的安全异常。和这个一样。 Android bluetooth print stopped working on 4.1

如果可能的话,我有什么办法可以做到这一点?

【问题讨论】:

    标签: android bluetooth apk file-transfer


    【解决方案1】:

    将 .apk 重命名为 .zip 并发送,然后在手机上将其重命名为 .apk。

    【讨论】:

    • 好吧,我确实做到了,我使用 ZipOutputStream 压缩文件然后发送它们。
    • 你能提供这个ZipOutputStream的小样本吗?
    【解决方案2】:

    通过将Intent 中的 MIME 类型更改为application/zip,我能够获得运行 4.4.2 的库存 Nexus 7 来发送 APK。但这仍然没有改变接收 APK 的障碍。但由于许多/大多数 ROM 删除了该块,因此能够从库存 ROM 发送 APK 仍然很有用。

    PackageManager pm = getPackageManager();
    ApplicationInfo appInfo;
    try {
        appInfo = pm.getApplicationInfo("org.fdroid.fdroid",
                PackageManager.GET_META_DATA);
        Intent sendBt = new Intent(Intent.ACTION_SEND);
        // NOT THIS! sendBt.setType("application/vnd.android.package-archive");
        sendBt.setType("application/zip");
        sendBt.putExtra(Intent.EXTRA_STREAM,
                Uri.parse("file://" + appInfo.publicSourceDir));
        sendBt.setClassName("com.android.bluetooth",
                "com.android.bluetooth.opp.BluetoothOppLauncherActivity");
        startActivity(sendBt);
    } catch (NameNotFoundException e1) {
        e1.printStackTrace();
    }
    

    这是一个简单的示例,因为它只针对我在两台设备上看到的一个蓝牙Activity (com.android.bluetooth.opp.BluetoothOppLauncherActivity)。不幸的是,Activity 并不总是调用它(例如,com.broadcom.bt.app.opp.OppLauncherActivity),甚至包名称也可能不同(例如,com.mediatek.bluetooth)。

    处理方法如下:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-07
      • 2011-06-02
      • 2011-11-14
      • 2011-08-13
      • 2012-04-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多