I have used Intent-SEND to share the files via bluetooth.I have add my code here.

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

This code is not working in android version 4.2.2. While running this code in android verison 4.2.2 , getting Exception:

        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?

But this code working fine in below android 4.2.X. why this code is not working in android 4.2.2?.

有帮助吗?

解决方案

You can share the file by bluetooth like this:

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

其他提示

Try setting the packageName instead of the component

intent.setPackage("com.android.bluetooth");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top