سؤال

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