0

如果 Twitter 应用程序本身没有登录用户,我使用 ACTION_SEND 在 Twitter 8.11.0 上遇到崩溃。

我已经在 Twitter 8.10.0 等较低版本的 twitter 上进行了尝试,它工作正常。

这是我当前的代码

Intent tweetIntent = new Intent(Intent.ACTION_SEND);
tweetIntent.putExtra(Intent.EXTRA_TEXT, checkStringFormat());
tweetIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
tweetIntent.setType("text/plain");

PackageManager packManager = getPackageManager();
List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(tweetIntent, PackageManager.MATCH_DEFAULT_ONLY);

boolean resolved = false;
for (ResolveInfo resolveInfo : resolvedInfoList) {
     if (resolveInfo.activityInfo.packageName.startsWith("com.twitter.android")) {
           tweetIntent.setClassName(resolveInfo.activityInfo.packageName, 
           resolveInfo.activityInfo.name);
           resolved = true;
           break;
     }
}

if (resolved) {
      startActivity(tweetIntent);
} else {
      routeToWebView();
}

通常,如果 twitter 应用程序中没有会话,则 ACTION_SEND 意图会将您路由到 twitter 的登录页面。

这是我收到的错误消息

2019-09-05 15:03:54.409 29626-29626/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.twitter.android, PID: 29626
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.twitter.android/com.twitter.composer.ComposerActivity}: java.lang.IllegalStateException: NullableUtils.checkIsNotNull(userInfo.userName) must not be null
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3303)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3411)
        at android.app.ActivityThread.-wrap12(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1994)
        at android.os.Handler.dispatchMessage(Handler.java:108)
        at android.os.Looper.loop(Looper.java:166)
        at android.app.ActivityThread.main(ActivityThread.java:7529)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
     Caused by: java.lang.IllegalStateException: NullableUtils.checkIsNotNull(userInfo.userName) must not be null
        at o16.a(Twttr:1)
        at c16.<init>(Twttr:5)
        at d16.get(Twttr:2)
        at d16.get(Twttr:1)
        at jqb.get(Twttr:6)
        at com.twitter.composer.selfthread.l0.get(Twttr:2)
        at com.twitter.composer.selfthread.l0.get(Twttr:1)
        at jqb.get(Twttr:6)
        at com.twitter.android.app.di.DaggerTwitterApplicationObjectGraph$Scythe$Component$d$x3$b.g(Twttr:1)
        at bt3.a(Twttr:12)
        at vs3.onCreate(Twttr:2)
        at em3.onCreate(Twttr:2)
        at ro3.onCreate(Twttr:1)
        at android.app.Activity.performCreate(Activity.java:7383)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3256)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3411) 
        at android.app.ActivityThread.-wrap12(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1994) 
        at android.os.Handler.dispatchMessage(Handler.java:108) 
        at android.os.Looper.loop(Looper.java:166) 
        at android.app.ActivityThread.main(ActivityThread.java:7529) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921) 

4

0 回答 0