Intent.migrateExtraStreamToClipData() on a null object reference

Seems like the error occurs on devices where Google Play Services are not installed, passed intent will then be null.

You can make sure intent passed is not null by overriding startActivityForResult method in your Activity.

@Override    
public void startActivityForResult(Intent intent, int requestCode) {
    if (intent == null) {    
        intent = new Intent();        
    }       
    super.startActivityForResult(intent, requestCode);
}

This actually worked for me.

For Android 11 (API level 30) or higher, in AndroidManifest.xml,

<queries>
        <package android:name="com.google.android.youtube" />
        <package android:name="com.example.app" />
</queries>

"If your app targets Android 11 (API level 30) or higher and needs to interact with apps other than the ones that are visible automatically, add the element in your app's manifest file. Within the element, specify the other apps by package name."

Refer here for more details.


This question is a bit old, but I just wanted to share an update on it. According to this Github issue on the GCM project the issue should be solved in Google Play Services version 9.4.0. The accepted answer should work as well (as an intermediate patch), but if you update your Google Play Services library this issue should be solved.