【问题标题】:How to make my Android app appear in the share list of another specific app如何让我的 Android 应用出现在另一个特定应用的共享列表中
【发布时间】:2012-06-21 03:32:10
【问题描述】:
<action android:name="android.intent.action.SEND" />     
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />

这是在我的清单文件中

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

【问题讨论】:

    标签: android android-intent filter share


    【解决方案1】:

    在应用外部分享内容时,在你想先打开的activity中添加这段代码,在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" );
        }
    }
    

    在清单中添加这个,

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

    【讨论】:

      【解决方案2】:

      为此,您需要知道应用程序正在创建的 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>
      

      应用程序的名称和共享的内容将帮助我给出更具体的回复。

      【讨论】:

      • 我希望我的应用仅出现在“Google play 应用”的分享列表中。当您尝试共享应用程序时。它共享文本,但许多其他应用程序使用相同的东西!我可以过滤文本的内容吗??!!
      • 我认为这是不可能的。检查意图表明它确实非常笼统。
      【解决方案3】:

      - 在特定活动中将以下代码添加到您的项目 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"));
                  }
      

      【讨论】:

      • 嗨@Bhavik 任何其他权限添加应用程序端?我尝试但不工作
      • 在我的情况下实际上不需要。您试用的是哪种设备?
      【解决方案4】:

      将此添加到您的 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

      【讨论】:

        【解决方案5】:

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

        以下是这段代码的结果:

          <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

        【讨论】:

          【解决方案6】:

          我想在上述答案中添加一些内容。请记住,如果您在一个活动中使用多个类别,您应该放置另一个意图过滤器以防止覆盖。

          例如,以下内容将阻止您的应用程序显示在您设备的应用程序列表中,因为它不会将其检测为启动器活动。

          不要这样做

              <application
                  android:allowBackup="true"
                  android:icon="@mipmap/ic_launcher"
                  android:label="@string/app_name"
                  android:roundIcon="@mipmap/ic_launcher_round"
                  android:supportsRtl="true"
                  android:theme="@style/AppTheme">
          
                  <activity android:name=".MainActivity">
          
                      <intent-filter>
                          <action android:name="android.intent.action.MAIN" />
                          <category android:name="android.intent.category.LAUNCHER" />
                
                          <!-- DO NOT DO THIS-->
          
                          <action android:name="android.intent.action.SEND" />
                          <category android:name="android.intent.category.DEFAULT" />
                          <data android:mimeType="*/*" />
                      </intent-filter>
          
                  </activity>
              </application>
          

          改为跟随

              <application
                  android:allowBackup="true"
                  android:icon="@mipmap/ic_launcher"
                  android:label="@string/app_name"
                  android:roundIcon="@mipmap/ic_launcher_round"
                  android:supportsRtl="true"
                  android:theme="@style/AppTheme">
          
                  <activity android:name=".MainActivity">
          
                      <intent-filter>
                          <action android:name="android.intent.action.MAIN" />
                          <category android:name="android.intent.category.LAUNCHER" />
                      </intent-filter>
          
                      <!-- USE SEPERATE INTENT FILTER -->
          
                      <intent-filter>
                          <action android:name="android.intent.action.SEND" />
                          <category android:name="android.intent.category.DEFAULT" />
                          <data android:mimeType="*/*" />
                      </intent-filter>
          
                  </activity>
              </application>
          

          注意:根据你的使用改变mimeType。

          结论:如果您在意图过滤器中使用多个类别,请分别使用它们。

          【讨论】:

          • 帮助很大。谢谢。在一些中国品牌设备上运行良好。
          【解决方案7】:

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

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

        • 为您的过滤器提供更具体的隐式操作
        • 或者添加除 DEFAULT 以外的类别
        • 如果你能找到类似的东西,它就不太可能被其他应用程序看到。

          【讨论】:

            猜你喜欢
            • 2023-03-04
            • 2014-02-07
            • 2021-11-07
            • 2020-11-22
            • 1970-01-01
            • 1970-01-01
            • 2016-06-06
            • 1970-01-01
            • 2016-09-09
            相关资源
            最近更新 更多