Java Android studio共享youtube链接到我的应用程序
我已经在清单中插入了这个Java Android studio共享youtube链接到我的应用程序,java,android,Java,Android,我已经在清单中插入了这个 <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:host="www.youtube.com" androi
<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>
但是我不知道如何在我的活动中获得链接,当你添加意图过滤器时,你允许你的应用程序由youtube启动,因此你需要检查你的应用程序是否由youtube启动 你可以先得到意图,然后再得到意图的行动 在活动的onCreate方法中,使用以下代码:
// 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);
}