'How to Share Youtube Link to my Application?

I want to get link shared from YouTube to my application using the built-in option of share in YouTube. The link is then auto pasted in an edit text in my application The problem is when my APP is closed and an intent is shared to my app ,the link is shared and pasted in edit text but when the app is open ,YouTube opens my app but does not share the link to my app. The code is as follows

ANDROID MANIFEST FILE IS AS BELOW

 <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

THE LOGIC TO RECEIVE INTENT IS AS BELOW

void handleSendText(Intent intent) {
    String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);

    if (sharedText != null) {
        ((EditText) findViewById(R.id.linktext)).setText(sharedText);
    }
}

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


    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {

            handleSendText(intent); // Handle text being sent
        } else {
            // Handle other intents, such as being started from the home screen
        }
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source