如何让我的 Android 应用出现在另一个特定应用的共享列表中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11095122/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:58:34  来源:igfitidea点击:

How to make my Android app appear in the share list of another specific app

androidandroid-intentfiltershare

提问by Android Ninja

<action android:name="android.intent.action.SEND" />     
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />

this is in my manifest file

这是在我的清单文件中

this will make my app appear on the share list of all apps but I want my app to appear in the share list of another specific app and I don't own the other app

这将使我的应用程序出现在所有应用程序的共享列表中,但我希望我的应用程序出现在另一个特定应用程序的共享列表中,并且我不拥有其他应用程序

采纳答案by DanO

In order to do this, you need to know the Intent that the application is creating and create an IntentFilter that will add your application to the specific list.

为此,您需要知道应用程序正在创建的 Intent 并创建一个 IntentFilter 将您的应用程序添加到特定列表。

Receiving an Implicit Intenton Intents and Filters (Android Developers)

意图和过滤器接收隐式意图(Android 开发人员)

The application probably uses a specific action name that you could hook to.

该应用程序可能使用您可以挂钩的特定操作名称。

<intent-filter . . . >
    <action android:name="com.example.project.SHOW_CURRENT" />
    <action android:name="com.example.project.SHOW_RECENT" />
    <action android:name="com.example.project.SHOW_PENDING" />
    . . .
</intent-filter>

Or it could be looking for applications accepting a certain type of file.

或者它可能正在寻找接受某种类型文件的应用程序。

<intent-filter . . . >
    <data android:mimeType="video/mpeg" android:scheme="http" . . . /> 
    <data android:mimeType="audio/mpeg" android:scheme="http" . . . />
    . . .
</intent-filter>

The name of the application and what it is sharing would help me give a more specific response.

应用程序的名称及其共享的内容将帮助我给出更具体的响应。

回答by Soropromo

Add this code in the activity you want opened first when sharing a content from outside the app, call this method in onCreate()

从应用程序外部共享内容时,将此代码添加到您要首先打开的活动中,在 onCreate() 中调用此方法

private void onSharedIntent() {
    Intent receiverdIntent = getIntent();
    String receivedAction = receiverdIntent.getAction();
    String receivedType = receiverdIntent.getType();

    if (receivedAction.equals(Intent.ACTION_SEND)) {

        // check mime type 
        if (receivedType.startsWith("text/")) {

            String receivedText = receiverdIntent
                    .getStringExtra(Intent.EXTRA_TEXT);
            if (receivedText != null) {
                //do your stuff
            }
        }

        else if (receivedType.startsWith("image/")) {

            Uri receiveUri = (Uri) receiverdIntent
                    .getParcelableExtra(Intent.EXTRA_STREAM);

            if (receiveUri != null) {
                //do your stuff
                fileUri = receiveUri;// save to your own Uri object

                Log.e(TAG,receiveUri.toString());
            }
        }

    } else if (receivedAction.equals(Intent.ACTION_MAIN)) {

        Log.e(TAG, "onSharedIntent: nothing shared" );
    }
}

Add this in Manifest,

在清单中添加这个,

 <activity
            android:name="your-package-name.YourActivity">
            <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>

回答by med116

this worked well for me for getting all web pages, for my appthat scans for mp3 files on a web page, and sets alarms from them. It opens up my new url activity, when you share a web page:

这对我获取所有网页、扫描网页上的 mp3 文件并设置警报的应用程序都很有效。当您共享网页时,它会打开我的新网址活动:

Here is what this code results in: enter image description here

下面是这段代码的结果: 在此处输入图片说明

  <activity
        android:name=".NewUrl"
        android:label="@string/title_activity_new_url"
        android:windowSoftInputMode="stateUnchanged">
        <intent-filter>
            <action android:name="android.intent.action.SEND"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="text/*"/>
        </intent-filter>
    </activity>

Then to receive the link in the app, I got awsome info from this tutorial: http://code.tutsplus.com/tutorials/android-sdk-receiving-data-from-the-send-intent--mobile-14878

然后为了接收应用程序中的链接,我从本教程中获得了一些信息:http: //code.tutsplus.com/tutorials/android-sdk-receiving-data-from-the-send-intent--mobile-14878

回答by Bhavik Nathani

enter image description here- Add below code into your Project AndroidManifest.xml file in Specific Activity.

在此处输入图片说明- 将以下代码添加到特定活动中的项目 AndroidManifest.xml 文件中。

     <activity
                android:name=".MainActivity"
                android:theme="@style/Theme.AppCompat.Light.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/plain" />
            </intent-filter>
     </activity>

- Add the following line of code into your project specific Activity.

- 将以下代码行添加到您的项目特定活动中。

    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();
    if ("android.intent.action.SEND".equals(action) && type != null && "text/plain".equals(type)) {
                Log.println(Log.ASSERT,"shareablTextExtra",intent.getStringExtra("android.intent.extra.TEXT"));
            }

回答by AbuQauod

add this to your mainefist file

将此添加到您的 mainefist 文件中

<activity android:name=".ShareActivity">
<intent-filter
    android:label="Share with my app">
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

this link may help you

这个链接可以帮助你

回答by WineGoddess

I would check to see if there is any API for this app you want to work with.

我会检查是否有您想要使用的此应用程序的任何 API。

If so, you can benefit by knowing

如果是这样,您可以通过了解而受益

  • a more specific implicit action for your filter
  • 过滤器的更具体的隐式操作
  • or perhaps add a category other than DEFAULT
  • 或者可能添加除 DEFAULT 以外的类别
  • If you can find something like these, it would be unlikely to be seen by other apps.

    如果你能找到这样的东西,其他应用程序就不太可能看到它。