【问题标题】:How to find whether the app is called by "Share-Via"?如何查看应用程序是否被“Share-Via”调用?
【发布时间】:2013-10-07 14:23:20
【问题描述】:

我已将我的 Android 应用程序添加到“Share-Via”窗口。以下代码添加到我的代码的onCreate() 方法中。

        if(getIntent().getAction().equals(Intent.ACTION_SEND))
        {
            String text = getIntent().getStringExtra(Intent.EXTRA_TEXT);
            textField.setText(text);
        }

现在的问题是,如果此应用程序活动从共享通过调用,它可以工作。但是,如果它被直接调用(用户打开应用程序 -> 转到该活动),这将与 NullPointerException 一起崩溃。我在这里得到NullPointerException

if(getIntent().getAction().equals(Intent.ACTION_SEND))

以下是此 Share-Via 在清单文件中的配置方式。

<activity
            android:name="com.xx.xx.xx"
            android:screenOrientation="portrait"
            android:label="@string/app_name" >

            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/plain"/>
            </intent-filter>

        </activity>

这里有什么问题?

【问题讨论】:

  • if (Intent.ACTION_SEND.equals(getIntent().getAction()) {?
  • 当然这并不能防止getIntent成为null,仅适用于getAction

标签: java android eclipse android-intent android-activity


【解决方案1】:

getIntent()getAction() 正在返回 null
你需要检查一下。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-26
    • 1970-01-01
    • 2012-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-22
    • 1970-01-01
    相关资源
    最近更新 更多