Phonegap Build WebIntent Plugin: Intent-Filter in config.xml für AndroidManifest.xml

Um das Plugin WebIntent im Build-Service von Phonegap nutzen zu können, werden zusätzliche Intent-Filter in der AndroidManifest.xml benötigt.

In der config.xml kann beim Tag gap:config-file die Option mode=“add“ genutzt werden, damit die Optionen von Build.Phonegap nicht verloren gehen (und die App noch normal gestartet werden kann).

config.xml

<?xml version="1.0" encoding="UTF-8"?>

<!-- config.xml reference: https://build.phonegap.com/docs/config-xml -->
<widget xmlns = "http://www.w3.org/ns/widgets&quot;
xmlns:gap = "http://phonegap.com/ns/1.0&quot;
xmlns:android = "http://schemas.android.com/apk/res/android&quot;
id = "com.phonegap.build.apps1284xxx"
version = "2015.1.26.10">

<name>DemoWebIntent</name>

<description>
PG 3.4.0 / V010 (2015.1.26.10)
</description>

<author href="https://build.phonegap.com/apps/1284xxx/&quot; email="xxx.xxx@gmail.com">
WebIntent
</author>

<content src="index.html" />

<!-- <gap:platform name="ios" /> -->
<gap:platform name="android" />
<!-- <gap:platform name="winphone" /> -->

<preference name="phonegap-version" value="3.4.0" /> <!-- all: current version of PhoneGap -->
<preference name="orientation" value="portrait" /> <!-- all: 'default' means both 'landscape' and 'portrait' are enabled -->
<preference name="fullscreen" value="false" /> <!-- all: hides the status bar at the top of the screen -->

<!-- iOS PREFERENCES -->
<preference name="target-device" value="universal" /> <!-- all: possible values handset, tablet, or universal -->
<preference name="prerendered-icon" value="true" /> <!-- ios: if icon is prerendered, iOS will not apply it's gloss to the app's icon on the user's home screen -->
<preference name="ios-statusbarstyle" value="black-opaque" /> <!-- ios: black-translucent will appear black because the PhoneGap webview doesn't go beneath the status bar -->
<preference name="detect-data-types" value="true" /> <!-- ios: controls whether data types (such as phone no. and dates) are automatically turned into links by the system -->
<preference name="exit-on-suspend" value="false" /> <!-- ios: if set to true, app will terminate when home button is pressed -->

<preference name="webviewbounce" value="false" />
<preference name="stay-in-webview" value="false" />
<preference name="show-splash-screen-spinner" value="false" />
<preference name="auto-hide-splash-screen" value="false" /> <!-- if set to false, the splash screen must be hidden using a JavaScript API -->

<preference name="disable-cursor" value="false" /> <!-- blackberry: prevents a mouse-icon/cursor from being displayed on the app -->

<!-- ANDROID PREFERENCES -->

<preference name="android-minSdkVersion" value="7" /> <!-- minimum Android 2.1 -->
<!-- <preference name="android-maxSdkVersion" value="19" /> maximum Android 4.4 -->
<preference name="android-targetSdkVersion" value="19" /> <!-- targeting Android 4.4 -->
<preference name="android-installLocation" value="auto" />
<preference name="android-windowSoftInputMode" value="stateUnspecified|adjustUnspecified" /> <!-- Keyboard nicht anzeigen, wenn App laed -->
<preference name="splash-screen-duration" value="2000" />
<preference name="load-url-timeout" value="20000" />

<!-- Plugins -->

<!-- Core plugins -->
<gap:plugin name="org.apache.cordova.camera" />
<gap:plugin name="org.apache.cordova.device" />
<gap:plugin name="org.apache.cordova.file" />
<gap:plugin name="org.apache.cordova.geolocation" />
<gap:plugin name="org.apache.cordova.inappbrowser" />
<gap:plugin name="org.apache.cordova.network-information" />
<gap:plugin name="org.apache.cordova.splashscreen" />

<feature name="http://api.phonegap.com/1.0/camera"/&gt;
<feature name="http://api.phonegap.com/1.0/file"/&gt;
<feature name="http://api.phonegap.com/1.0/geolocation"/&gt;
<feature name="http://api.phonegap.com/1.0/network"/&gt;

<icon src="icon.png" />
<gap:splash src="splash.png" />

<access origin="*"/>

<gap:plugin name="com.virtualartifacts.webintent" version="1.0.0" />
<gap:config-file
platform="android"
parent="/manifest/application"
mode="add"
>
<!-- Share empfangen -->
<activity
android:name="DemoWebIntent"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden"
>
<intent-filter>
<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"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:host="www.youtube.com" android:scheme="http"></data>
<data android:host="www.youtube.com" android:scheme="https"></data>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="text/*" />
</intent-filter>
</activity>
</gap:config-file>

</widget>

index.html

<html>
<head>
<title>Demo WebIntent</title>
<script src="cordova.js"></script>
<script src="webintent.js"></script>
<script>
function init() {
document.addEventListener("deviceready",deviceReady,false);
}
function deviceReady() {
// console.log("Device Ready");
window.plugins.webintent.getUri(function(url) {
if(url !== "") {
// url is the url the intent was launched with
document.querySelector("#test").innerHTML = "URL was "+url;
}
});
}
</script>
</head>
<body onload="init()">
<h1>Demo WebIntent</h1>
<hr/>
<div id="test"></div>
</body>
</html>

webintent.js

/**
* cordova Web Intent plugin
* Copyright (c) Boris Smus 2010
*
*/
(function(cordova){
var WebIntent = function() {

};

WebIntent.prototype.ACTION_SEND = "android.intent.action.SEND";
WebIntent.prototype.ACTION_VIEW= "android.intent.action.VIEW";
WebIntent.prototype.EXTRA_TEXT = "android.intent.extra.TEXT";
WebIntent.prototype.EXTRA_SUBJECT = "android.intent.extra.SUBJECT";
WebIntent.prototype.EXTRA_STREAM = "android.intent.extra.STREAM";
WebIntent.prototype.EXTRA_EMAIL = "android.intent.extra.EMAIL";
WebIntent.prototype.ACTION_CALL = "android.intent.action.CALL";
WebIntent.prototype.ACTION_SENDTO = "android.intent.action.SENDTO";

WebIntent.prototype.startActivity = function(params, success, fail) {
return cordova.exec(function(args) {
success(args);
}, function(args) {
fail(args);
}, 'WebIntent', 'startActivity', [params]);
};

WebIntent.prototype.hasExtra = function(params, success, fail) {
return cordova.exec(function(args) {
success(args);
}, function(args) {
fail(args);
}, 'WebIntent', 'hasExtra', [params]);
};

WebIntent.prototype.getUri = function(success, fail) {
return cordova.exec(function(args) {
success(args);
}, function(args) {
fail(args);
}, 'WebIntent', 'getUri', []);
};

WebIntent.prototype.getExtra = function(params, success, fail) {
return cordova.exec(function(args) {
success(args);
}, function(args) {
fail(args);
}, 'WebIntent', 'getExtra', [params]);
};

WebIntent.prototype.onNewIntent = function(callback) {
return cordova.exec(function(args) {
callback(args);
}, function(args) {
}, 'WebIntent', 'onNewIntent', []);
};

WebIntent.prototype.sendBroadcast = function(params, success, fail) {
return cordova.exec(function(args) {
success(args);
}, function(args) {
fail(args);
}, 'WebIntent', 'sendBroadcast', [params]);
};

window.webintent = new WebIntent();

// backwards compatibility
window.plugins = window.plugins || {};
window.plugins.webintent = window.webintent;
})(window.PhoneGap || window.Cordova || window.cordova);

Advertisements

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s

%d Bloggern gefällt das: