Twitter PostActivity issue

2019-04-11 23:41发布

问题:

This intent has stoppped working . It was working for 2 months

2 month ago class name has changed from "com.twitter.android.PostActivity" to "com.twitter.applib.PostActivity" . I think it changed again. Is it changed again again and again ?

Can anyone help me to post tweet ?

and sorry about my english

try {
                        getPackageManager().getPackageInfo(
                                "com.twitter.android", 0);

                        Intent twitterIntent = new Intent(
                                Intent.ACTION_VIEW);

                        String twitterVersionName = getPackageManager()
                                .getPackageInfo("com.twitter.android",
                                        0).versionName;

                        VersionControl currentVersion = new VersionControl(
                                twitterVersionName);
                        VersionControl requestedVersion = new VersionControl(
                                "4.1.9");
                        if (currentVersion.compareTo(requestedVersion) > -1) {
                            twitterIntent.setClassName(
                                    "com.twitter.android",
                                    "com.twitter.applib.PostActivity");
                        } else {
                            twitterIntent.setClassName(
                                    "com.twitter.android",
                                    "com.twitter.android.PostActivity");
                        }
                        twitterIntent.putExtra(Intent.EXTRA_TEXT,
                                tweetText);
                        startActivity(twitterIntent);
                    } catch (NameNotFoundException e) {
                        try {
                            startActivity(new Intent(
                                    Intent.ACTION_VIEW,
                                    Uri.parse("https://twitter.com/intent/tweet?source=webclient&text="
                                            + URLEncoder.encode(
                                                    tweetText, "UTF-8"))));
                        } catch (UnsupportedEncodingException e1) {
                            e1.printStackTrace();
                        }
                    }

回答1:

You don't need to search for exact name , you can try like this,

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("*/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Your text here");
shareIntent.putExtra(Intent.EXTRA_STREAM, screenShot);
String appName = "twitter"; 

// use also instagram, pinterest, mail etc for appName.(not facebook)

final PackageManager pm = _activity.getPackageManager();
final List<?> activityList = pm.queryIntentActivities(shareIntent, 0);
int len = activityList.size();
Log.d("Tag","Length: "+len);
for (int i = 0; i < len; i++) 
{
    final ResolveInfo app = (ResolveInfo) activityList.get(i);
    Log.d("Apps on share list: "+ app.activityInfo.name);
    if ((app.activityInfo.name.contains(appName))) 
    {
        Log.d("Tag","Found package: "+app.activityInfo.name);
        final ActivityInfo activity = app.activityInfo;
        final ComponentName name = new ComponentName(activity.applicationInfo.packageName,    activity.name);
        shareIntent.setComponent(name);
        //TODO change your activity here
        _activity.startActivityForResult(shareIntent,SHARE_REQUEST_CODE);

        return;
    }
}
// not found so make default redirecting
Log.d("Tag","Not Found package: ");


回答2:

Twitter change "com.twitter.applib.PostActivity" to "com.twitter.applib.composer.TextFirstComposerActivity"