通过 intent linkedin 共享因权限被拒绝而崩溃

Sharing via intent linkedin crashing with permission denial

我正在尝试通过 linkedin 应用分享内容

这是代码

<activity
            android:name=".MainActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/title_activity_main_activity2"
            android:launchMode="singleTop"
            android:exported="true"
            android:screenOrientation="portrait"
            android:theme="@style/NoActionBarAppTheme">

            <intent
                android:action="android.intent.action.SEND"
                android:targetPackage="com.linkedin.android"
                android:targetClass="com.linkedin.android.home.v2.UpdateStatusActivity"
                />

            </activity>

我的意图代码是

 if(Utilities.doesPackageExist(getActivity(), "com.linkedin.android"))
                {
                    Intent shareIntent = new Intent(Intent.ACTION_SEND);
                    shareIntent.setClassName("com.linkedin.android",
                            "com.linkedin.android.home.v2.UpdateStatusActivity");
                    shareIntent.setType("text/plain");
                    shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareText);
                    startActivity(shareIntent);
                }
                else
                {
                    Toast.makeText(getActivity(), "Please install the LinkedIn app to share your result", Toast.LENGTH_LONG).show();
                }

我收到这个错误

java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.SEND typ=text/plain flg=0x1 cmp=com.linkedin.android/.home.v2.UpdateStatusActivity (has clip) (has extras) } from ProcessRecord{538be710 4331:com.devicebee.workedin/u0a98} (pid=4331, uid=10098) not exported from uid 10131

Here is the code

Android 清单中没有 <intent> 元素,至少根据 the documentation

I get this error

如错误消息所示,您尝试使用的 activity 未导出。 "Not exported" 表示第三方应用无法启动 activity。它是 LinkedIn 应用程序的专用 activity;只有 LinkedIn 应用程序可以启动 activity.

在应用程序标签的 android 清单文件中设置此代码。

 <intent-filter>
        <action android:name="android.intent.action.SEND" />

        <category android:name="android.intent.category.DEFAULT" />

        <data android:mimeType="image/*" />
    </intent-filter>

您可能还想通过官方 Linked Android SDK 在 Android 上执行 LinkedIn 分享,这是官方支持的方法。您可以在此处下载 SDK:https://developer.linkedin.com/downloads#androidsdk

有关如何使用它共享内容的详细信息,请参见此处:https://developer.linkedin.com/docs/share-on-linkedin