java - 如何判断app是否被 "Share-Via"调用?

标签 java android eclipse android-intent android-activity

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

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

现在的问题是,如果从共享途径调用此应用程序 Activity ,它就可以工作。但是,如果直接调用它(用户打开应用程序 -> 转到该 Activity ),则会因 NullPointerException 崩溃。我在这里收到 NullPointerException

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

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

<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>

这里有什么问题吗?

最佳答案

getIntent()getAction() 返回 null
您需要检查一下。

关于java - 如何判断app是否被 "Share-Via"调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19227330/

相关文章:

java - 如何在eclipse便携版中设置jdk?

java - 自动将类添加到源代码管理

安卓文件处理

java - 用户输入正确答案后,如何停止重复此循环?

java - 在Java中读取带有重音字符的文件

java - 单击 GlassPane 时在 GlassPane 后面的 JPanel 上绘图

android - 尝试将 ADT 插件安装到 Eclipse 时发生依赖冲突

java - 如何对弹力球实现声明?

java - 如何对已开发的 Web 应用程序使用 dropwizard

java - 为什么此 XML 会产生 "...must be well-formed"验证错误?