title: How to add share menu item to Gallery by code
body: <p>I know how to implement this issue by Menuifest.xml, see also:</p>
  
  <p><a href="http://groups.google.com/group/android-developers/browse_thread/thread/62a514363c751464/feecc033d0265606?lnk=gst&amp;q=intentfilter+share#feecc033d0265606" rel="nofollow noreferrer">Google Android Developer Group related issue</a></p>
  
  <p>But my question is how to add share menu of Gallery by java code not Menuifest.xml.</p>
  
  <p>My code is as below:</p>
  
  <pre><code>public class MyActivity extends Activity {
  
  private static final String TAG = "MyActivity";
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      IntentFilter intentFilter = new IntentFilter();
      intentFilter.addAction(Intent.ACTION_SEND);
      intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
      try {
          intentFilter.addDataType("image/*");
      } catch (MalformedMimeTypeException e) {
          Log.e(TAG, e.toString());
      }
  
      Intent x = registerReceiver(new BroadcastReceiver() {
          public void onReceive(Context context, Intent intent) { 
              Log.d(TAG, "Received intent "+intent);
              intent.setComponent(new ComponentName(context, Uploader.class));
              startActivity(intent);
          }
          }, intentFilter);
  
      if (x==null)
          Log.i(TAG, "failed to regist a receiver");
      else
          Log.i(TAG, "registed a receiver successfully");
      // ...
  </code></pre>
  
  <p>But registerReceiver always return null, and there is no menu added to Gallery's Share.</p>
  
  <p>Thank you.</p>
  
  <p>Anthony Xu</p>