【问题标题】:How to know that an Activity has been started by a given Intent?如何知道某个 Activity 已由给定 Intent 启动?
【发布时间】:2013-08-15 12:19:20
【问题描述】:

我正在使用here 提供的代码登录 Twitter。回调地址为oauth://t4jsampleintent-filter如下图所示。

它运行良好,但是当 MainActivity 从这个 Intent 开始时,我想重新加载包含我的 Twitter 登录 ButtonFragment 以显示一条消息“你登录为 ... ”。

我怎么知道MainActivity已经被Twitter网页发送的Intent启动了?我可以得到Intent 的操作,但我如何确保它不是由其他东西发送的?

意图过滤器

<activity android:name=".MainActivity" ... >
    ...
    <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="t4jsample"
            android:scheme="oauth" />
    </intent-filter>
</activity>

【问题讨论】:

    标签: android android-intent


    【解决方案1】:

    你可以使用getIntent().getData(),它会给出与意图相关的数据的Uri。如果它匹配oauth://t4jsample,那么你可以确定它来自twitter并且你可以做相应的改变

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-20
      相关资源
      最近更新 更多