无法找到显式活动类(蓝牙)

时间:2017-03-01 06:31:15

标签: android android-intent bluetooth

早上好

我正在尝试通过蓝牙将Excel文件发送到PC,但我收到以下错误:

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?

我处理发送操作的代码是:

private void ShareReportToPc() {
        File file = new File(Environment.getExternalStorageDirectory() + "/CoiAppFiles/COI-Report.xls");
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("application/excel");
        intent.setClassName("com.android.bluetooth", "com.android.bluetooth.opp.BluetoothOppLauncherActivity");
        intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        startActivity(intent);
    }

Manifest的代码是:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="iq.nazaha.wissam.CoiApp">

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.NoActionBar">
        <activity
            android:name=".LoginPage"
            android:configChanges="orientation"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainPage"
            android:configChanges="orientation"
            android:screenOrientation="portrait" />
        <activity
            android:name=".AddNewItemPage"
            android:configChanges="orientation"
            android:screenOrientation="portrait" />
        <activity
            android:name=".EditItemPage"
            android:configChanges="orientation"
            android:screenOrientation="portrait" />
        <activity
            android:name=".ReportsPage"
            android:configChanges="orientation"
            android:screenOrientation="portrait" />
        <activity
            android:name=".AboutPage"
            android:configChanges="orientation"
            android:screenOrientation="portrait" />
    </application>

</manifest>

我搜索了很多答案,其中一些建议在AndroidManifest中包含我已经做过的活动名称,其他人建议清理项目但是它没有解决问题。我相信这是一个非常愚蠢的错误,但我失明了。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

我建议将intent.setClassName("com.android.bluetooth", "com.android.bluetooth.opp.BluetoothOppLauncherActivity");替换为intent.setPackage("com.android.bluetooth");