Marco Montalto Marco Montalto - 1 month ago 18
Android Question

How to launch an Ionic application and NOT open it in a web view?

I'm stuck at the same issue for 2 days :(

I have two

Ionic-PhoneGap
applications that need to the be able to open each other, NOT in a
WebView
, but externally (if the app is already running, it can be restarted or just continue - I will handle both).

After many hours of research, I found that, using
InAppBrowser (window.open(URL, _system))
, I was able to open externally every commercial application I tried (facebook, twitter, maps, etc). The same call, when trying to open one of my applications, opens it in a web view.

window.open("fb://", _system) -> opens Facebook separately.
window.open("myapp://", _system) -> opens my application in a web view.


I've tried to modify
AndroidManifest.xml
and the
config.xml
, but almost everything I changed is erased by the building.

For example, if I change
"android:launchMode="singleTop"
to
"android:launchMode="singleTask"
and I run "Ionic build", my change are lost..

Any solution?

Answer

SOLUTION FOUND!!!

Need to add those lines in app/config.xml :

<preference name="AndroidLaunchMode" value="singleTask" />
<access origin="*" launch-external="yes" />

and change android:lauchMode to "Single Task" in app/platforms/android/AndroidManifest.xml :

...

<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">
<activity android:launchMode="singleTask" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"  android:label="@string/activity_name" android:name="MainActivity" android:theme="@android:style/Theme.Black.NoTitleBar" 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>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="fkapp" />
    </intent-filter>
</activity>

...

Hope it will help someone!!

Comments