android启动第三方sevice,ComponentName 启动第三方app的Activity或者Service

本文介绍了如何使用ComponentName来启动第三方应用的Activity或Service。通过指定包名和组件全名,可以创建ComponentName实例并配合Intent进行启动操作。同时提到了启动系统应用如媒体库和相机的方法,并强调了被启动组件需要设置android:exported="true"以允许外部调用。
摘要由CSDN通过智能技术生成

ComponentName

顾名思义,就是组件名称,通过调用intent.setComponent()方法,我们可以打开另一个应用的Activity或者Service

创建ComponentName 需要两个参数:

(1)第三方应用的包名

(2)要打开的Activity和Service的全名称(包名+类名)

public ComponentName(@NonNull String pkg, @NonNull String cls) {

if (pkg == null) throw new NullPointerException("package name is null");

if (cls == null) throw new NullPointerException("class name is null");

mPackage = pkg;

mClass = cls;

}

启动第三方Acitivity

ComponentName chatActivity =new ComponentName("com.feifei.example", "com.feifei.example.ChatActivity");

Intent intent =new Intent();

intent.setComponent(chatActivity);

startActivity(intent);

启动第三方Service

ComponentName chatService =new ComponentName("com.feifei.example", "c

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值