Marco Montalto
Marco Montalto

Reputation: 215

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?

Upvotes: 2

Views: 6787

Answers (3)

Marco Montalto
Marco Montalto

Reputation: 215

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!!

Upvotes: 8

ryziek
ryziek

Reputation: 41

To change the launchMode property add the following in ./config.xml:

<platform name="android">
    <preference name="android-launchMode" value="singleTask"/>
</platform>

Also make sure to edit ./hooks/after_prepare/030_update_platform_config.js. There are lines:

var preferenceMappingData = {
    'android': {
        ...
        'android-launchMode': {target: 'AndroidManifest.xml', parent: 'application/activity[@android:name=\'CordovaApp\']', destination: 'android:launchMode'},
        ...
    }
};

Make sure that the parent attribute is corresponding correctly to your activity in ./platforms/android/AndroidManifest.xml. In my case I had to change \'CordovaApp\' to \'MainActivity\'.

Then you just run ionic build android and the property should be changed in manifest.

Upvotes: 1

Vadiem Janssens
Vadiem Janssens

Reputation: 4109

You should take a look at this plugin: https://github.com/EddyVerbruggen/Custom-URL-scheme. The functionality you're looking for can be accomplished by URL scheme's.

Also, never directly modify a file in the /platforms/ folder. Ionic (cordova) generates these files, that's why you keep losing your changes. If you want to edit those files, you may take a look at cordova's hooks.

Upvotes: 2

Related Questions