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

问题描述 投票:16回答:6
<action android:name="android.intent.action.SEND" />     
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />

这是在我的清单文件中

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

android android-intent filter share
6个回答
7
投票

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

Receiving an Implicit IntentIntents and Filters (Android Developers)

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

<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>

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

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

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


7
投票

在应用程序外部共享内容时首先要打开的活动中添加此代码,在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" );
    }
}

在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>

6
投票

这对我来说非常适合获取所有网页,my app可以扫描网页上的mp3文件,并设置它们的警报。当您共享网页时,它会打开我的新网址活动:

以下是此代码的结果: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>

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


4
投票

将其添加到清单文件中

<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


3
投票

enter image description here-将以下代码添加到Specific Activity中的Project 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>

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

    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"));
            }

0
投票

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

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

  • 您的过滤器的更具体的隐式操作
  • 或者添加DEFAULT以外的类别
  • 如果你能找到类似这样的东西,那么其他应用就不太可能看到它。

    © www.soinside.com 2019 - 2024. All rights reserved.