Активность java не найдена

#android #cordova #plugins #path #manifest

#Android #кордова #Плагины #путь #манифест

Вопрос:

Я создаю свой собственный плагин cordova для Android. Однако, когда я вызываю реализацию activity в плагине cordova из моего приложения cordova, кажется, что мой файл activity java не обнаруживается моим приложением cordova.

В то время как logcat заявил,

android.content.ActivityNotFoundException: не удается найти явный класс активности {my.app.path/my.plugin.path.SampleActivity}; вы объявили это действие в своем AndroidManifest.xml ?

Как ни странно, путь моего плагина связан с путем моего приложения. Я почти уверен, что я объявил свою активность в AndroidManifest.xml в моем плагине cordova.

Фрагмент (AndroidManifest.xml )

 <activity android:name="my.plugin.path.SampleActivity"
        android:screenOrientation="portrait">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>
  

Фрагмент (plugin.xml )

 <config-file target="AndroidManifest.xml" parent="app/src/main/application">
    <activity android:name="my.plugin.path.SampleActivity" 
        android:screenOrientation="portrait" 
        android:configChanges="orientation">
    </activity>
</config-file>
  

Фрагмент (PluginInterface.java )

 @Override
public boolean execute(String action, CordovaArgs args, CallbackContext mCallbackContext) throws JSONException {

    this.mCallbackContext = mCallbackContext;

    Context context = cordova.getActivity().getApplicationContext();
    Intent intent = new Intent(context, SampleActivity.class);

    return true;
}
  

Буду признателен, если кто-нибудь сможет помочь. Спасибо.

Ответ №1:

Проблема решена. Проблемы заключаются в plugin.xml . Изменив с

 <config-file target="AndroidManifest.xml" parent="app/src/main/application">
  <activity android:name="my.plugin.path.SampleActivity" 
    android:screenOrientation="portrait" 
    android:configChanges="orientation">
  </activity>
</config-file>
  

Для

 <config-file target="AndroidManifest.xml" parent="/manifest/application">
  <activity android:name="my.plugin.path.SampleActivity" 
    android:screenOrientation="portrait" 
    android:configChanges="orientation">
  </activity>
</config-file>
  

полностью решает проблему.