我使用Intent-SEND通过蓝牙共享文件。我在这里添加了我的代码。
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setComponent(new ComponentName("com.android.bluetooth",
"com.android.bluetooth.opp.BluetoothOppLauncherActivity"));
intent.setType("text/plain");
File file = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/Sample.txt");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
startActivity(intent);
此代码在Android 4.2.2版中无效。在android verison 4.2.2中运行此代码时,获取异常:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.bluetooth/com.android.bluetooth.opp.BluetoothOppLauncherActivity}; have you declared this activity in your AndroidManifest.xml?
但是这个代码在android 4.2.X下运行正常。为什么这段代码在android 4.2.2中不起作用?。
答案 0 :(得分:1)
您可以通过蓝牙共享文件,如下所示:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(picURI);
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Sample.txt");
sharingIntent.setType("text/plain");
sharingIntent.setPackage("com.android.bluetooth");
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
startActivity(Intent.createChooser(sharingIntent, "Share file"));
答案 1 :(得分:0)
尝试设置packageName而不是组件
intent.setPackage("com.android.bluetooth");