android 启动服务setaction,如何从另一个Android应用程序启动Android服务

我从另一个

Android应用程式开始服务时遇到问题(API 17).

但是,如果我从shell运行’am’,服务开始正常.

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

我没有意图过滤器的服务,我不想设置一个,我真的想知道我做错了什么开始它的组件名称,或什么可能使它不可能这样做.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值