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 ...
随机推荐
- 三分钟学会CSS3中的FLEXBOX布局
原文地址,保护版权,请勿转载:http://page.factj.com/blog/p/2574 这篇文章里我们将学习CSS里flexbox布局的几个最重要的概念,通过学习flexbox布局,你会发现 ...
- MySQL的记录长度
MySQL的记录长度 MySQL默认规定一条记录最大的长度是65535字节,所有的字段加在一起所占的字节数不能超过65535.但是MySQL中字段的长度有的时使用字节来规定int,有些字段类型是使用字 ...
- Windows下lex 与 yacc的使用(2)
Windows下lex 与 yacc的使用 ...
- sql的集合操作
原文转自:http://blog.csdn.net/qsyzb/article/details/12560917 SELECT语句的查询结果是元组的集合,所以多个SELECT语句的结果可进行集合操作. ...
- 第9条:覆盖equals时总要覆盖hashCode
在每个覆盖equals方法的类中,也必须覆盖hashCode方法.否则,会违反Object.hashCode的通用约定,从而导致该类无法结合所有基于散列的集合一起正常工作,包括HashMap,Hash ...
- Linux C 程序 两变量值交换(FIVE)
example:1.运算符: #include<stdio.h> int main(){ int a , b , c ,d ; a = ; b = a++;//先赋值给b,a再自增 c = ...
- 升级iOS10后SearchController焦点无法获取的问题
原来在没升级之前,是这样获取的,好使 - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.sea ...
- compass(sass)+seajs+frozenui+frozenjs+svn主干分支
1.compass框架 sass编译 1.compass create 项目名 2.cd目录,执行compass watch 2.frozen框架 js(frozen.js),css(global.c ...
- 【python】坑,坑,折腾一个下午python 3.5中 ImportError: No module named BeautifulSoup
将语句 from bs4 import BeautifulSoup4 改成 from bs4 import BeautifulSoup 通过 尼玛------------------------! 总 ...
- C#中的==、Equal、ReferenceEqual(转载)
1. ReferenceEquals, == , Equals Equals , == , ReferenceEquals都可以用于判断两个对象的个体是不是相等. a) ReferenceEquals ...