英文:
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
<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>
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);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论