使用 WebIntent Native Plugin 从 intent-filter 获取 Intent



我正在使用 Ionic Native Plugin Web Intent,我想获取一个 android Intent 并在我的应用程序中使用媒体文件或您的本地 URL。 我的安卓清单.xml没关系,我可以将MyApp视为共享或选择图像的选项。

<action android:name="android.intent.action.PICK"/> 
<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="image/*"/>

但是我被锁定了,试图在我的应用程序中获得这个意图。

我尝试使用本机插件 https://ionicframework.com/docs/native/web-intent/但是收到响应错误"plugin_not_installed"。

constructor(private _platform: Platform,
private _webIntent: WebIntent
) {
}
...
ionViewDidLoad() {
this._platform.ready().then(() => {
this._webIntent.getIntent().then((data: any) => {
// Use data from intent
}).catch((error:any) => console.log(error));
});
}

使用 Android 版本 5.0.1 进行调试。

如果有人能帮助我!我真的很感激!

Obs.:我读了 https://forum.ionicframework.com/t/webintent-plugin-not-installed/96744,但我没有看到任何解决方案。

您必须将Intent Filter添加到AndroidManifest.xml。

<intent-filter>
<action android:name="android.intent.action.PICK"/> 
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*"/>
</intent-filter>

然后在构造函数中,在设备处于就绪状态后执行此操作。

if (window.plugins){
window.plugins.webintent.hasExtra(window.plugins.webintent.EXTRA_STREAM,
function(hasIt){
if (hasIt) {
window.plugins.webintent.getExtra(window.plugins.webintent.EXTRA_STREAM,
function(streamData){
console.log(streamData);
}, function(err){
console.log(err);
});
}
},function(err){
console.log(err);
});
}

你应该在构造函数中移动getIntent()

最新更新