我从另一个Android应用程序(API 17)启动服务时遇到问题。 但是,如果我确实从shell运行'am',则服务启动正常。如何从另一个Android应用程序启动Android服务
# am startservice com.xxx.yyy/.SyncService
Starting service: Intent { act=android.intent.action.MAIN cat=
[android.intent.category.LAUNCHER] cmp=com.xxx.yyy/.SyncService }
(service starts fine at this point)
# am to-intent-uri com.xxx.yyy/.SyncService
intent:#Intent;action=android.intent.action.MAIN;
category=android.intent.category.LAUNCHER;
component=com.xxx.yyy/.SyncService;end
所以,它看起来并不像我从意向缺少什么,当我做同样的代码:
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setComponent(new ComponentName("com.xxx.yyy", ".SyncService"));
ComponentName c = ctx.startService(i);
if (c == null) { Log.e(TAG, "failed to start with "+i); }
我得到的是(服务未在运行那段时间):
E/tag(4026): failed to start with Intent {
act=android.intent.action.MAIN
cat=[android.intent.category.LAUNCHER]
cmp=com.xxx.yyy/.SyncService }
我没有对服务的意图过滤器,我不希望设置一个,我真的想了解我在做什么错,通过启动它的组件名称,或者可能使其变得不可能乐来这样做。
参考http://saigeethamn.blogspot.in/2009/09/android-developer-tutorial-part-9.html – Richa
@Richa这个页面有使用Intent.setClassName()的例子,但它并不真的回答我的具体问题... –
发布您的清单 –