我可以分享到我的NativeScript应用程序吗? [英] Can I share to my NativeScript app?
问题描述
在NativeScript的当前状态下是否可以创建一个监听Android上共享意图的应用?
Is it possible in current state of NativeScript to create an app which listens for share intents on Android?
例如,我想实现的目标是在Android的网络浏览器中打开一个网站,点击共享",然后在共享目标列表中查看我的NativeScript应用.
What I would like to achieve is for example having a website opened in my web browser on Android, tap on share and see my NativeScript app on the list of share targets.
我确实在本地Android应用程序上完成了此操作,但无法使其在NativeScript应用程序上工作.我搞砸了要添加的AndroidManifest.xml
I did accomplish this on a native Android app but can't get it to work in a NativeScript app. I've messed with the AndroidManifest.xml to add
<action android:name="android.intent.action.SEND"></action>
<category android:name="android.intent.category.DEFAULT"></category>
放入intent-filter,但这没有帮助.我的应用程序未显示在共享目标列表中.
into intent-filter but this did not help. My app does not show up in the list of share targets.
推荐答案
NativeScript应该立即支持这种情况.这是我在默认引导应用程序的app/App_resources/Android
中的AndroidManifest的样子:
NativeScript should support this scenario out of the box. Here's what my AndroidManifest in app/App_resources/Android
of a default bootstrapped application looks like:
<activity
android:name="com.tns.NativeScriptActivity"
android:label="@string/title_activity_kimera"
android:configChanges="keyboardHidden|orientation|screenSize">
<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.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
将意图发送到其他任何应用程序的非常简单的实现:
edit: Very simple implementation to send intent to any of my other application:
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra("string", "the data Im sending you");
Intent chooser = Intent.createChooser(sendIntent, "Share with ");
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
}
});
这篇关于我可以分享到我的NativeScript应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!