4
我知道如何實現由Menuifest.xml這個問題佔有率菜單項添加到庫,另見:如何通過代碼
Google Android Developer Group related issue
但我的問題是,如何通過Java來添加畫廊的共享菜單代碼不是Menuifest.xml。
我的代碼如下:
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");
// ...
但registerReceiver總是返回null,並沒有加入到庫的共享菜單。
謝謝。
安東尼徐