如何在不移动其他应用程序的情况下使用意图共享

huangapple go评论69阅读模式
英文:

How to use intent share without moving another app

问题

以下是翻译好的部分:

我想在浏览器上使用意图共享按钮,通过重叠屏幕,而不是切换到另一个应用程序。

这是我的 AndroidManifest.xmlSendActivity.java

<activity
  android:name=".SendActivity"
  android:launchMode="singleTop"
  android:theme="@style/LaunchTheme">  
  <intent-filter>
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <!-- <category android:name="android.intent.category.BROWSABLE" /> -->
    <data android:mimeType="text/plain" />
  </intent-filter>
</activity>
package com.example.my_app;

import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;

import java.nio.ByteBuffer;

public class SendActivity extends Activity { }

这是我的情况。当我点击一个应用程序时,屏幕会切换到另一个应用程序。

我想像下面的 Pocket 应用程序一样打开 sendActivity。

如有需要,欢迎继续提问。

英文:

I want to use intent share button on browser by overlapping screen, not moving to another app.

This is my AndroidManifest.xml and SendActivity.java

&lt;activity
  android:name=&quot;.SendActivity&quot;
  android:launchMode=&quot;singleTop&quot;
  android:theme=&quot;@style/LaunchTheme&quot;&gt;  
  &lt;intent-filter&gt;
    &lt;action android:name=&quot;android.intent.action.SEND&quot; /&gt;
    &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
    &lt;!-- &lt;category android:name=&quot;android.intent.category.BROWSABLE&quot; /&gt; --&gt;
    &lt;data android:mimeType=&quot;text/plain&quot; /&gt;
  &lt;/intent-filter&gt;
&lt;/activity&gt;
package com.example.my_app;

import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;

import java.nio.ByteBuffer;

public class SendActivity extends Activity { }

This is my situation. When I click an app, the screen moves to another app.

如何在不移动其他应用程序的情况下使用意图共享

I want to open sendActivity like pocket app in below.

如何在不移动其他应用程序的情况下使用意图共享

答案1

得分: 1

如果您想在不打开另一个应用程序的情况下发送数据,那么您可以编写一个本地运行的服务。

Flutter应用程序将调用一个方法通道,将要共享的数据传递给该服务,然后由后台服务处理,我相信自Android 8以来,其生命周期限制为10分钟。此服务将处理共享并可以将数据发送到另一个服务器或另一个广播接收器。

然而,如果您需要用户能够配置如何发送他们的数据(使用哪个应用程序),发送给谁等等,则需要在设备上使用绑定活动。

您可以使用以下软件包来管理此过程:

此软件包允许您将文件共享到其他应用程序:https://pub.dev/packages/flutter_share

而这个软件包则允许您分享简单的文本:https://pub.dev/packages/share

英文:

If you want to send data without opening another app, then you could write up a service which will run natively.

The flutter app will invoke a method channel, that will pass the data to be shared to that service, then it's up to the background service, which I believe since Android 8 has a lifespan limit of 10 minutes. This service will then handle the sharing and can send the data off to another server, or another broadcast receiver.

However if you need the user to be able to configure how they want to send their data (which app), who they will send it to, etc, then you will need to use a bound activity on the device.

You can use these packages to manage this:

This package allows you to share files into other applications: https://pub.dev/packages/flutter_share

And this package allows you to share simple text: https://pub.dev/packages/share

huangapple
  • 本文由 发表于 2020年10月16日 09:24:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/64381724.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定