How to add a sharing menu item to the gallery by code

I know how to implement this problem with Menuifest.xml, see also:

Problem with Google Android Developer Team

But my question is how to add a gallery sharing menu using java code, not Menuifest.xml.

My code is as follows:

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"); // ... 

But registerReceiver always returns null, and no menu has been added to the Share gallery.

Thanks.

Anthony Xu

+4
source share
1 answer

I set this quest in the google android development group and the android team member gave me the answer: thread in the android group

Hope this helps you.

+1
source

All Articles