【问题标题】:onResume method not working for Twitter ImplementationonResume 方法不适用于 Twitter 实现
【发布时间】:2013-02-23 08:11:51
【问题描述】:

尝试将 Twitter 与我的应用程序集成。按照教程进行操作,但它不起作用。

我有一个PreferenceActivity,它有一个CheckBoxPreference。如果点击,我会执行以下操作:

chkTwitter.setOnPreferenceClickListener(new OnPreferenceClickListener() {           
    @Override
    public boolean onPreferenceClick(Preference _pref) {
        Intent fbIntent = new Intent(getApplicationContext(), TwitterConnectActivity.class);
        _pref.setIntent(fbIntent);
        return false;
    }
});

我的 TwitterConnectActivity 被调用,我在那里配置 Oauth 对象并调用 Twitter 的身份验证网站。

当我点击 Authorize App 时,我的 onResume 被调用:

@Override
    protected void onResume() {
        super.onResume();
        if (this.getIntent()!=null && this.getIntent().getData()!=null){
            Uri uri = this.getIntent().getData();

            if (uri != null && uri.toString().startsWith(CALLBACK_URL)) {
                String verifier = uri.getQueryParameter(oauth.signpost.OAuth.OAUTH_VERIFIER);

问题是this.getIntent().getData() 为空,所以我从不进入 if 条件。

我的 AndroidManifest 如下所示:

 <activity
            android:name=".SettingsActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="my_twitter" android:scheme="callback" />
            </intent-filter>
        </activity>
        <activity
            android:name=".TwitterConnectActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
        </activity>

当然,我将回调 URL 定义为:private String CALLBACK_URL = "callback://my_twitter";

谁能帮帮我?

干杯, 费利佩

【问题讨论】:

  • +1 教我一个聪明的小技巧,使用点击处理程序动态设置 PreferenceIntent :)
  • 我不知道我是否正确,因为我有一段时间没有将 Twitter 添加到应用程序中,但您是否需要使用 onNewIntent?
  • 很高兴我帮助了@Devunwired :) Catherine oneNewIntent 方法将被调用,具体取决于我在那里使用 launchMode 属性的方式,我只是使用普通方法,所以我认为不会调用 onNewIntent .我去看看!
  • 非常非常奇怪...我什么都没做,现在Intent中的数据来了。好吧,那好吧!

标签: android twitter


【解决方案1】:

改用 StartActivityForResult。

【讨论】:

    猜你喜欢
    • 2021-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-13
    • 2016-10-01
    • 2012-04-23
    • 2013-06-19
    • 1970-01-01
    相关资源
    最近更新 更多