从图书馆项目到主项目的意图

ida*_*dan 0 android android-intent android-library

当我尝试使用意图从主项目传递到库项目时,它工作正常,但是......当我尝试从库项目传递到主项目时,它无法识别主项目中的类。

我尝试在我的图书馆项目中写下这个意图:

Intent intent = new Intent(this,com.example.uploadvideo.class);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

我将我想要连接的两个活动添加到主项目和库项目的清单中。

在此输入图像描述

MrC*_*haz 5

库项目不知道主项目。我认为首选的解决方案是使用操作,而不是尝试直接在意图中加载类。如果您想重用该库,这也将为您提供更大的灵活性。

所以图书馆会做

Intent intent = new Intent("com.example.action_video_upload");
intent.setPackage(mContext.getPackageName()); // only deliver to host app
Run Code Online (Sandbox Code Playgroud)

主项目将在清单中注册该意图

<intent-filter . . . >
    <action android:name="com.example.action_video_upload" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)

更多信息可以在这里找到:developer.android.com