Android add my app to “Share” button in gallery

浪子不回头ぞ 提交于 2019-12-03 12:21:53

问题


I succeed to add my app in the "share" button in the Android gallery, so if I click on it, my app will start. Can I choose which activity of my app to start? Now it starts the "main" one. Here's my code in the main class:

    .....        
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    String action = intent.getAction();

    // if this is from the share menu
    if (Intent.ACTION_SEND.equals(action)) {   
        if (extras.containsKey(Intent.EXTRA_STREAM)) {
            // Get resource path
        }
    }

And the manifest:

<intent-filter>
   <action android:name="android.intent.action.SEND" />
   <category android:name="android.intent.category.DEFAULT" />
   <data android:mimeType="image/*" />
</intent-filter>

In reality I succeed in opening a new activity immediately after the "main" starts but I'll prefer to directly open the right one. Thanks


回答1:


Put your intent filter under activity you want to start into your manifest

 <activity android:name=".Theme"
           android:label="MAIN">
   <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
</activity>

 <activity android:name=".Theme"
           android:label="ActiVITY2">
  <intent-filter>
   <action android:name="android.intent.action.SEND" />
   <category android:name="android.intent.category.DEFAULT" />
   <data android:mimeType="image/*" />
  </intent-filter>
</activity>



回答2:


If you had two activities in your manifest file, say Main and MediaShare then it would look something like this:

<activity android:name="Main" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
<activity android:name="MediaShare" >
    <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <data android:mimeType="image/*" />
    </intent-filter>
</activity>

The android.intent.action.SEND action and android:mimeType="image/*" data should go with the activity you want to start when you share an image.

See the page on Receiving Content from Other Apps for more details.



来源:https://stackoverflow.com/questions/13609458/android-add-my-app-to-share-button-in-gallery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!