2013-10-07 69 views
0

我已将我的Android应用程序添加到“Share-Via”窗口。以下代码被添加到我的代码的onCreate()方法中。如何查找应用程序是否由“Share-Via”调用?

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

现在的问题是,如果这个应用程序活动被从共享通路调用,它的工作原理。但是,如果它直接被调用(用户打开应用程序 - >去那个活动),这与NullPointerException崩溃。我在这里

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

越来越NullPointerException右以下是本次股份通过清单文件如何配置的。

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

这里有什么问题?请帮忙。

+0

'if(Intent.ACTION_SEND.equals(getIntent()。getAction()){'? –

+0

@hins:非常感谢! –

+0

当然,这并不能防止'getIntent'为'null', 'getAction'。 –

回答

4

getIntent()getAction()返回null
你需要检查。

+0

是的,那是对的 –

相关问题