Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android studio共享youtube链接到我的应用程序_Java_Android - Fatal编程技术网

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);
    }