我已将 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/