Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何查找应用程序是否由“调用”;“通过”共享;?_Java_Android_Eclipse_Android Intent_Android Activity - Fatal编程技术网

Java 如何查找应用程序是否由“调用”;“通过”共享;?

Java 如何查找应用程序是否由“调用”;“通过”共享;?,java,android,eclipse,android-intent,android-activity,Java,Android,Eclipse,Android Intent,Android Activity,我已将我的Android应用程序添加到“共享通过”窗口。下面的代码被添加到我的代码的onCreate()方法中 if(getIntent().getAction().equals(Intent.ACTION_SEND)) { String text = getIntent().getStringExtra(Intent.EXTRA_TEXT); textField.setText(text); }

我已将我的Android应用程序添加到“共享通过”窗口。下面的代码被添加到我的代码的
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))
下面是如何在清单文件中配置此共享

<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

您需要检查它。

要么
getIntent()
要么
getAction()
返回
null


你需要检查它。

如果(Intent.ACTION\u SEND.equals(getIntent().getAction()){
?当然,这不能防止
getIntent
null
,只有
getAction
如果(Intent.ACTION\u SEND.equals)(getIntent().getAction()){?当然,这不能防止
getIntent
null
,仅适用于
getAction