-1

I am building an app with which other apps can share text (links etc).

Is there a way to get the name of the app that is sharing data with my app?

I already found refer.host witch gives me the URI of the sharing app but the URIs differ (com.reddit.frontpage vs com.google.android.youtube) which makes parsing hard.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
liquid.pizza
  • 505
  • 1
  • 10
  • 26

1 Answers1

0

Add this code in your Manifests

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >

        //Add this line
        <intent-filter>
            <action android:name="android.intent.action.GET_CONTENT" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:mimeType="*/*" />
        </intent-filter>
        //---------------

    </activity>
</application>

Now Add this code in MainActivity to get share data by other app

public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Get intent, action and MIME type
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    // You would then use these three variable to figure out who has sent you an Intent and what they want you to do!
    // See here for further instruction: https://developer.android.com/training/sharing/receive.html
    // https://developer.android.com/guide/topics/manifest/action-element.html
    // https://developer.android.com/reference/android/content/Intent.html#ACTION_GET_CONTENT

}
}

I hope this can help you!

Thank You.

Hardik Talaviya
  • 1,396
  • 5
  • 18