On Android API 19 (4.4) the intent.createChooser method causes IntentServiceLeak

后端 未结 2 624
醉酒成梦
醉酒成梦 2021-01-12 09:33

Running my app on the new Android KitKat device (API 19, 4.4) I get \"Copied to Clipboard\" everytime I try to create an Intent chooser. This is happening on Youtube, Tumbl

2条回答
  •  不要未来只要你来
    2021-01-12 10:06

    Here's my workaround solution for this issue. I first detect if the device is running on KIT_KAT or higher, and instead of creating a chooser, I simply try to start the intent. This will cause Android to ask the user which application they want to complete the action with (unless the user already has a default for all ACTION_SEND intents.

    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    sendIntent.putExtra(Intent.EXTRA_TEXT, message);
    sendIntent.setType("text/plain");
    
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // This will open the "Complete action with" dialog if the user doesn't have a default app set.
        context.startActivity(sendIntent);
    } else {
        context.startActivity(Intent.createChooser(sendIntent, "Share Via"));
    }
    

提交回复
热议问题