katzer / cordova-plugin-email-composer

Edit and send email messages
Apache License 2.0
345 stars 336 forks source link

Queries are not added to AndroidManifest.xml #377

Closed randnetdd closed 2 years ago

randnetdd commented 2 years ago

The code below is written in plugin.xml Queries are not added to AndroidManifest.xml.

    <config-file target="app/src/main/AndroidManifest.xml" parent="/manifest/queries">
        <intent>
            <action android:name="android.intent.action.SENDTO" />
            <data android:scheme="mailto" />
        </intent>
    </config-file>

It has been confirmed that it will be added when rewritten to the code below

    <config-file target="AndroidManifest.xml" parent="/*">
        <queries>
            <intent>
                <action android:name="android.intent.action.SENDTO" />
                <data android:scheme="mailto" />
            </intent>
        </queries>
    </config-file>

Is the committed plugin.xml correct?

Environment information

Runtime issue

Android build issue:

jfoclpf commented 2 years ago

did you install this plugin from this repo?

cordova plugin add https://github.com/katzer/cordova-plugin-email-composer.git

randnetdd commented 2 years ago

I installed it from npm

cordova plugin add cordova-plugin-email-composer

I also installed it from git, but plugin.xml was the same

After that, I downloaded ZIP from git and installed it locally, but it was not added to AndroidManifest.xml. Finally, when I edited and installed the local plugin.xml, it was added to AndroidManifest.xml.

jfoclpf commented 2 years ago

if you install from npm you have to remove and install again from git, as the npm version is outdated

try brute force (unix or macos)

cordova plugin remove cordova-plugin-email-composer
cordova plugin add https://github.com/katzer/cordova-plugin-email-composer.git
rm -rf platforms/ plugins/
cordova platform rm android
cordova platform add android 
jfoclpf commented 2 years ago

The code below is written in plugin.xml Queries are not added to AndroidManifest.xml.

    <config-file target="app/src/main/AndroidManifest.xml" parent="/manifest/queries">
        <intent>
            <action android:name="android.intent.action.SENDTO" />
            <data android:scheme="mailto" />
        </intent>
    </config-file>

It has been confirmed that it will be added when rewritten to the code below

    <config-file target="AndroidManifest.xml" parent="/*">
        <queries>
            <intent>
                <action android:name="android.intent.action.SENDTO" />
                <data android:scheme="mailto" />
            </intent>
        </queries>
    </config-file>

Is the committed plugin.xml correct?

Now I get your point, I need to check it when I arrive home.

How many AndroidManifest.xml are there under platforms/android?

randnetdd commented 2 years ago

As mentioned above, it is also installed from git. This installed in a completely new project

Write the contents of AndroidManifest.xml just in case

\platforms\android\app\src\main\AndroidManifest.xml

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="io.cordova.hellocordova" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:exported="true" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@style/Theme.AppCompat.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <provider android:authorities="${applicationId}.emailcomposer.provider" android:exported="false" android:grantUriPermissions="true" android:name="de.appplant.cordova.emailcomposer.Provider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/emailcomposer_provider_paths" />
        </provider>
    </application>
</manifest>
jfoclpf commented 2 years ago

Indeed I tested now and you're right, it does not pass into AndroidManifest.xml

This is enough to work

        <config-file target="AndroidManifest.xml" parent="/manifest/queries">
            <intent>
                <action android:name="android.intent.action.SENDTO" />
                <data android:scheme="mailto" />
            </intent>
        </config-file>

Indeed now the platforms/android/app/src/main/AndroidManifest.xml has

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.example.hello" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:exported="true" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@style/Theme.AppCompat.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <provider android:authorities="${applicationId}.emailcomposer.provider" android:exported="false" android:grantUriPermissions="true" android:name="de.appplant.cordova.emailcomposer.Provider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/emailcomposer_provider_paths" />
        </provider>
    </application>
    <queries>
        <intent>
            <action android:name="android.intent.action.SENDTO" />
            <data android:scheme="mailto" />
        </intent>
    </queries>
</manifest>

It seems the intent serves to send actions to other APPs

But what exactly were you trying to solve? Did you have any specific problem or bug? I'm not that versed in Android ecosystem, I'm just the maintainer of this repo, and thus I don't want to amend anything if we're not facing a problem/bug.

randnetdd commented 2 years ago

I found this Issues after confirming that the app crashes on Android 12 https://github.com/katzer/cordova-plugin-email-composer/issues/372

Also, from the error content, I confirmed that queryIntentActivities requires a queries element after Android 11. https://techblog.locoguide.co.jp/entry/2020/09/23/150010

And even if you install the plugin from git in a completely new project The queries element was missing in AndroidManifest.xml.

So I decided to refer to other plugins that add the queries element. https://github.com/dariosalvi78/cordova-plugin-health/blob/master/plugin.xml#L94-L104 https://github.com/apache/cordova-plugin-camera/blob/master/plugin.xml#L72-L86

I'm not familiar with the specifications of plugin.xml either. If I'm wrong please close this Issues

jfoclpf commented 2 years ago

Thank you, I just tested and indeed it does work and you were right, the queries were not being added.

Solved with 9d8324b748070d3f8a8283d9707f8e48ab633600

jfoclpf commented 2 years ago

BTW, could you test now just to be sure it is working?

randnetdd commented 2 years ago

I have confirmed that queries are added to AndroidManifest.xml when I add a plugin from git on a clean Android platform. However, it seems that empty queries remain in AndroidManifest.xml when the plugin is removed. I don't think it's that much of a problem

randnetdd commented 2 years ago

One problem is that 'parent="/manifest/queries"' seems to be a description method that adds to existing queries.

  1. cordova-plugin-camera
  2. cordova-plugin-email-composer

If you add plugins in this order, cordova-plugin-email-composer intent will be added to the queries added by cordova-plugin-camera.

  1. cordova-plugin-camera
  2. cordova-plugin-email-composer

If you remove plugins in this order, cordova-plugin-camera queries will not be removed and will remain in AndroidManifest.xml

  1. cordova-plugin-email-composer
  2. cordova-plugin-camera

If you remove plugins in this order you can remove all intents from queries

jfoclpf commented 2 years ago

If I understood correctly, the problem is just about the removal of the plugin, right?

randnetdd commented 2 years ago

yes

jfoclpf commented 2 years ago

I'm not sure but I think the problem is with the camera plugin here: https://github.com/apache/cordova-plugin-camera/blob/master/plugin.xml#L72

<config-file target="AndroidManifest.xml" parent="queries"> which should be <config-file target="AndroidManifest.xml" parent="/manifest/queries">

https://cordova.apache.org/docs/en/latest/plugin_ref/spec.html#config-file

but I am not sure

randnetdd commented 2 years ago

I overlooked one thing about cordova-plugin-camera plugin.xml is different between git and npm

https://github.com/apache/cordova-plugin-camera/issues/779 It looks like this hasn't been captured by npm yet

The above phenomenon occurs in npm but not in git

This problem is unavoidable unless you unify the query writing style of all plugins, so I think it's okay to end it.

jfoclpf commented 2 years ago

Great then, thanks for the feedback

TiBz0u commented 1 year ago

Thank you, I just tested and indeed it does work and you were right, the queries were not being added.

Solved with 9d8324b

Hi @jfoclpf, is there an explanation between this comment and the test you did on the initial correction. Is it due to cordova update?

jfoclpf commented 1 year ago

In this commit we added support for Android 11 (and the in the test I made, it worked) and with 9d8324b, after valuable information from @randnetdd we solved a bug on Android 12.