Error starting “com.twitter.android.PostActivity”

2019-05-06 21:33发布

问题:

I call a intent to Twitter to share a text. Without changing the code, from one day to another, this call has stopped working.

The Intent is:

Intent share = new Intent(Intent.ACTION_VIEW);
    share.setClassName("com.twitter.android",
            "com.twitter.android.PostActivity");
    share.setType("text/plain");

    share.putExtra(Intent.EXTRA_TEXT, getString(R.string.app_share_twitter));

    share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    startActivityForResult(share, SHARE_TWITTER);

Thanks

回答1:

The problem is the last Twitter Android app update (4.1.9)

The action that you call, have been changed to "com.twitter.applib.PostActivity". Try this to prevent the Exception launched in old/new Twitter versions:

try{
    startActivityForResult(share, SHARE_TWITTER);
}catch(Throwable e){
    share.setClassName("com.twitter.android", "com.twitter.applib.PostActivity");
    try{
        startActivityForResult(share, SHARE_TWITTER);
    }catch(Throwable e2){
        Log.e(TAG, e2.toString());                                              
    }}


回答2:

In July 2014, I've found that the Twitter activity has once again changed name, it is now called "com.twitter.android.composer.ComposerActivity".



回答3:

They have changed the activity that handle it...you can try now with setting this to your Intent:

   intent.setClassName("com.twitter.android", 
                     "com.twitter.composer.SelfThreadComposerActivity");


回答4:

The Twitter activity has once again changed name, it is now called "com.twitter.android.composer.ComposerShareActivity".