Android Studio分享YouTube链接到我的应用程序

huangapple go评论103阅读模式
英文:

Android studio share youtube link to my app

问题

我已经将这部分插入清单中:

<intent-filter>
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />              
    <data android:host="www.youtube.com" android:mimeType="text/*" />
</intent-filter>

但我不知道如何在我的活动中获取链接。

英文:

I already inserted this in manifest

&lt;intent-filter&gt;
&lt;action android:name=&quot;android.intent.action.SEND&quot; /&gt;
&lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;              
&lt;data android:host=&quot;www.youtube.com&quot; android:mimeType=&quot;text/*&quot; /&gt;
&lt;/intent-filter&gt;

But I couldn't know how Can I get the Link in my Activity

答案1

得分: 1

When you add that intent filter, you are allowing your app to be launched by YouTube, so you need to check if your app was actually launched by YouTube or not.

You can do this by first getting the intent and then getting the action of the intent.

In the onCreate method of your activity, use this code:

// Getting the intent that started your app
Intent intentThatStartedMyApp = getIntent();
// Getting the action associated with that intent
String actionOfTheIntentThatStartedMyApp = intentThatStartedMyApp.getAction();
// Checking the intent action
if (actionOfTheIntentThatStartedMyApp.equals(Intent.ACTION_SEND)) {
    Bundle extras = getIntent().getExtras();
    String stringContainingYouTubeLink = extras.getString(Intent.EXTRA_TEXT);
}
英文:

When you add that intent filter you are allowing your app to be launched by youtube, so you need to check if your app was actually launched by youtube or not.

You can do this by first getting the intent and then getting the action of the intent.

In the onCreate method of your activity use this code:

    // getting the intent that started your app
    Intent intentThatStartedMyApp = getIntent();
    // getting the action associated with that intent
    String actionOfTheIntentThatStartedMyApp = intentThatStartedMyApp.getAction();
    // checking the intent action
    if(actionOfTheIntentThatStartedMyApp.equals(Intent.ACTION_SEND)) {
        Bundle extras = getIntent().getExtras();
        String stringContainingYoutubeLink = extras.getString(Intent.EXTRA_TEXT);
    }

huangapple
  • 本文由 发表于 2020年8月12日 18:53:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/63375035.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定