Android开发之通过Intent启动其他App的Service
在Android5.0以前可以通过隐式Intent方式启动其他App的Service,就跟Activity启动隐式Intent一样的。
但是在5.0以后,只能使用显示的Intent方式启动了。
启动其他App的Service,需要用到Intent的setComponent()方法。该方法需要传入ComponentName component 这个参数。
参数的解释:component, The name of the application component to handle the intent, or null to let the system find one for you.
代码:
Intent serviceIntent;
private Button btnstartService;
private Button btnstopService;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
serviceIntent=new Intent();
serviceIntent.setComponent(new ComponentName("com.example.startservicefromanotherapp", "com.example.startservicefromanotherapp.AppService"));
btnstartService=(Button) findViewById(R.id.btnStartService);
btnstopService=(Button) findViewById(R.id.btnStopService);
btnstartService.setOnClickListener(this);
btnstopService.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btnStartService:
startService(serviceIntent);
break;
case R.id.btnStopService:
stopService(serviceIntent);
break;
}
}
这样就能启动其他App的Service。但是需要先设置其他App的Service的
android:exported="true"
否则会报错, java.lang.SecurityException: Not allowed to start service Intent { cmp=com.example.startservicefromanotherapp/.AppService } without permission not exported from uid 10075
提示没有权限。
Android开发之通过Intent启动其他App的Service的更多相关文章
- Android开发之通过Intent启动系统应用的协议
使用隐式Intent启动系统应用,除了http协议,还有geo(显示地理位置),tel(拨打电话),file(文件)等
- Android开发:怎样隐藏自己的app应用
本文主要介绍怎样通过改动AndroidManifest.xml清单文件来达到隐藏自身应用的目的,不是隐藏第三方应用.为了不浪费大家时间.特此说明. 转载请注明作者xiong_it和链接:http:// ...
- Android开发-API指南-Intent和Intent过滤器
Intents and Intent Filters 英文原文:http://developer.android.com/guide/components/intents-filters.html 采 ...
- Android开发3:Intent、Bundle的使用和ListView的应用 、RelativeLayout(相对布局)简述(简单通讯录的实现)
前言 啦啦啦~博主又来骚扰大家啦~大家是不是感觉上次的Android开发博文有点长呢~主要是因为博主也是小白,在做实验的过程中查询了很多很多概念,努力去理解每一个知识点,才完成了最终的实验.还有就是随 ...
- Android开发学习之Intent具体解释
Intent简单介绍和具体解释: Intent:协助应用间的交互与通信,Intent负责相应用中一次操作的动作.动作涉及的数据.附加数据进行描写叙述. ...
- Android开发中使用Intent跳转到系统应用中的拨号界面、联系人界面、短信界面
现在开发中的功能需要直接跳转到拨号.联系人.短信界面等等,查找了很多资料,自己整理了一下. 首先,我们先看拨号界面,代码如下: Intent intent =new Intent(); intent. ...
- 【Android开发那点破事】打开APP加载页面实现
今天的破事呢就说说APP加载页面的实现.一般情况下,当APP打开的时候,我们需要做很多事情,比如检查网络连接啊,初始化一些配置啊等等.我们可以让这些事情在APP完全打开之前做完,然后呢在打开的过程中显 ...
- 【Android开发】找乐,一个笑话App的制作过程记录
缘起 想做一个笑话App的原因是因为在知乎上看过一个帖子,做Android可以有哪些数据可以练手,里面推荐了几个数据开放平台.在这些平台中无一不是有公共的笑话接口,当时心想这个可以拿来练手啊,还挺有意 ...
- Android开发值利用Intent进行put传值,setclass启动activity,并用get进行取值
传值方法一 [java] Intent intent = new Intent(); Bundle bundle = new Bundle(); //该类用作携带数据 bundle.putString ...
随机推荐
- PC软件-实用工具 True Launch Bar
True Launch Bar 官网 增强及自定义window任务栏快捷方式管理. 有免费版的Free Launch Bar 官网
- xml simpleXML_load_file(), simpleXML_load_string()
xml.xml文件 <?xml version='1.0'?><man> <att> <name>lin3615</name& ...
- FireMonkey消息机制
interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Classes, FMX.Forms, FMX.Plat ...
- Super Hide IP 3.4.7.8允许您以匿名方式进行网上冲浪、 保持隐藏您的 IP 地址
Super Hide IP 3.4.7.8 转自:http://www.0daydown.com/04/695.html Super Hide IP允许您以匿名方式进行网上冲浪. 保持隐藏您的 IP ...
- 笨方法学python 33课
今天Eiffel看到了第33章,任务是把一个while循环改成一个函数. 我在把while循环改成函数上很顺利,但是不知道怎么写python的主函数,在参数的调用上也出现了问题. 通过查资料,发现py ...
- Python多线程启动http.server
OS: Windows 8.1 with update 关键字:Python3.4, http.server, Thread 例子代码如下: import os from threading impo ...
- keil 51警告编译优化
KeilC51中将工程中没有调用的函数不进行编译的方法 把Target Options中的Device页中选上"Use Extended Linker(LX51)instead of BL5 ...
- 数据库获取前N条记录SQL Server与SQLite的区别
在使用sql语句进行前20条记录查询时SQL Server可以这样写: 1: select top 20 * from [table] order by ids desc 2: select top ...
- javascript editor
http://www.jetbrains.com/webstorm/download/download_thanks.jsp?os=win
- appcache checking update
<!DOCTYPE html> <html manifest="a.appcache"> <head> <title></ti ...