Android 从另一个应用程序通过webintents向爱奥尼亚安卓应用程序发送url
正在寻找更新的解决方案,运行使用Cordova 5.x的最新ionic 1.1.0版本。尝试在chrome浏览器中浏览一个网站,并使用web意图将该url发送到我的爱奥尼亚安卓应用程序。我的应用程序编译并运行,但是当我试图使用chrome(或任何其他应用程序)的共享功能并选择要共享的应用程序时,我的应用程序崩溃 我首先尝试使用插件: 离子插件添加 然后删除了插件,我还尝试了最近更新的fork: 离子插件添加 在我的app.js文件中,我输入了以下代码:Android 从另一个应用程序通过webintents向爱奥尼亚安卓应用程序发送url,android,cordova,ionic-framework,ionic,Android,Cordova,Ionic Framework,Ionic,正在寻找更新的解决方案,运行使用Cordova 5.x的最新ionic 1.1.0版本。尝试在chrome浏览器中浏览一个网站,并使用web意图将该url发送到我的爱奥尼亚安卓应用程序。我的应用程序编译并运行,但是当我试图使用chrome(或任何其他应用程序)的共享功能并选择要共享的应用程序时,我的应用程序崩溃 我首先尝试使用插件: 离子插件添加 然后删除了插件,我还尝试了最近更新的fork: 离子插件添加 在我的app.js文件中,我输入了以下代码: .run(function($ionicP
.run(function($ionicPlatform, $rootScope, $ionicHistory, $state) {
$ionicPlatform.ready(function() {
window.plugins.webintent.getExtra(window.plugins.webintent.EXTRA_TEXT,
function(url) {
incomingURL = url;
//alert(incomingURL);
console.log(incomingURL);
}, function() {
incomingURL = false;
//alert("no url");
console.log("no url");
});
});
})
我还尝试:
.run(function($ionicPlatform, $rootScope, $ionicHistory, $state) {
$ionicPlatform.ready(function() {
window.plugins.webintent.getUri(function(url) {
if(url !== "") {
alert(url);//url is the url the intent was launched with
}
});
});
})
在config.xml文件中,我将:
<plugin name="WebIntent" value="com.borismus.webintent.WebIntent"/>
在AndroidManifest.xml中,我将手动输入:
<activity android:name="ShareActivity">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
应用程序正在运行,但当我转到chrome并单击“共享”按钮,然后选择“我的应用程序”时,应用程序将关闭,并显示以下android消息:
不幸的是,MyAppName已停止
有谁能提出一个解决方案,让共享的意图与我的应用程序一起工作…或者我忘记了什么,做了什么错事
谢谢大家! 发现问题是由于我如何设置AndroidManifest.xml文件造成的 我使用了一个额外的活动标签,而我本应该在1活动中包含意图 例如,我有:
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" 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>
</activity>
<activity android:name="ShareActivity">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
当我应该有:
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" 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.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
这个问题有点过时了。但我有一个或多或少类似的挑战。我没有幸使用WebIntent插件,因此我开发了自己的插件来处理Android上的意图 您可以检查以下内容: 虽然我还在为自己的项目开发这个插件,但它几乎是可用的,并且文档应该足够好,可以让我迈出一步 一些背景: 若要允许第三方应用向您的应用发送内容,您必须在AndroidManifest.xml中向MainActivity添加意图筛选器
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
成功后,您将收到一个有限意图对象。这可以由您的应用程序处理
例如:
{
"action": "android.intent.action.SEND_MULTIPLE",
"clipItems": [
{
"uri": "file:///storage/emulated/0/Download/example-document.pdf"
},
{
"uri": "file:///storage/emulated/0/Download/example-archive.zip"
}
],
"flags": 390070273,
"type": "*/*",
"component": "ComponentInfo{com.example.droid/com.example.droid.MainActivity}",
"extras": "Bundle[mParcelledData.dataSize=596]"
}
虽然此示例实际显示了JSON,但您将收到一个随时可用的对象
请注意,我开发插件目前只为我自己的需要。然而,它可能也适用于您。目前,自述文件中没有添加角度示例,但我认为这应该不是一个大问题 我想添加到@axel napolitano的答案中,以明确说明在Ionic 3应用程序中应该在何处添加代码。免责声明:我几乎无法编写Ionic应用程序 在撰写本文时,我目前正在使用Ionic 3.9。经过反复尝试和拼凑答案之后,我终于能够让它工作了(也就是说,在我的Ionic应用程序上共享另一个应用程序) 在这一点上,你应该已经编译了你的Android应用程序,并将你的Android手机连接到你的电脑上,这样应用程序就可以在上面运行了。查找有关如何在物理Android设备上运行ionic应用程序的文档 下面是命令:
ionic cordova运行android-l-c
您还应该将
添加到AndroidManifest.xml中
将代码放在/pages/home/home.ts中-确保构造函数已注入“平台”
export class HomePage {
constructor(private platform:Platform){
...
}
...
}
创建此方法(在home.ts中)以接收应用程序未处于加载状态时的意图:
ionViewDidLoad(){
this.platform.ready().then(() => {
(<any>window).plugins.intent.getCordovaIntent(
function (Intent) {
//you should filter on the intents you actually want to receive based on Intent.action
console.log('intent received on app launch' + JSON.stringify(Intent));
},
function () {
console.log('Error getting cordova intent');
}
);
});
}
ionViewDidLoad(){
this.platform.ready()。然后(()=>{
()-这是我无法实现的-归功于Napolitano的插件
我最终用同样的方法让darryncambell的插件工作。当我使用该插件时,它似乎对我很好,你关于config.xml中AndroidLaunchMode设置的一点对我非常有帮助。谢谢!@Axel Napolitano,我尝试使用你的插件,但是我很有兴趣,但是clipItems不见了。我是什么做错了吗?我的设置与插件页面上的设置完全相同。而且我收到了错误消息getRealPathFromContentUrl()不是一个函数。嘿,在过去的几个月里,我没有花太多时间在它上面,因为它对我有效。我会查看它,但由于我当前的工作量,无法保证立即解决。对此表示抱歉:-/我无法使darryncambell的插件工作。使用您的解决方案,它可以立即工作。谢谢
ionViewDidLoad(){
this.platform.ready().then(() => {
(<any>window).plugins.intent.getCordovaIntent(
function (Intent) {
//you should filter on the intents you actually want to receive based on Intent.action
console.log('intent received on app launch' + JSON.stringify(Intent));
},
function () {
console.log('Error getting cordova intent');
}
);
});
}
ionViewDidEnter() {
this.platform.ready().then(() => {
(<any>window).plugins.intent.setNewIntentHandler(
function (Intent) {
console.log('new intent' + JSON.stringify(Intent) );
}
);
});
}