启动第三方的Activity,service
来源:互联网 发布:虫虫钢琴软件 编辑:程序博客网 时间:2024/06/07 19:39
这两天一个新来的同事,我让他帮我写监控相关的功能,因为我让他把监控这个单独做成一个app, 里面涉及到自动登录,还有后台启动等相关的功能,
写了两周 ,功能做完了,但是代码质量不是很满意 ,里面涉及到Launcher中去启动监控app里面相关的界面,以及service,他是用广播来实现的,代码laucnher和监控app交互比较多,里面全是广播,我看了一下,感觉以后维护的同事会很难过 ,就整改了一下 ,所有的逻辑都写在监控app里面 ,Launcher仅仅是启动app里面的service就好 ,这样维护起来就简单多了
刚好就总结一下app启动第三方的Activity 和service , 网上的资源还是比较多的,这里做一个复合类的总结
app启动第三方的Activity的方法比较多
1:直接通过报名去启动Activity
Intent intent= getPackageManager().getLaunchIntentForPackage("com.reeman.demo");
startActivity(intent);
2:通过清单文件定义的Action
Intent intent = new Intent();
intent.setAction("com.reeman.demo");
startActivity(intent);
<intent-filter>
<action android:name="com.reeman.demo" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
3:通过Scheme
Intent intent = new Intent();
intent.setData(Uri.parse("joyodream://......"));
startActivity(intent);
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="joyodream" android:ssp="jiji" />
</intent-filter>
4:通过包名类名来打开Activty
ComponentName cmp = new ComponentName("com.tencent.mm","com.tencent.mm.plugin.sns.ui.SnsTimeLineUI");
intent.addCategory(Intent.CATEGORY_LAUNCHER);intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);intent.setComponent(cmp);startActivity(intent);
5:打开第三方的应用程序的Service
在自己的程序中启动
Intent intent = new Intent(); intent.setAction("com.mirror.mobile.action.START_SERVICE_MONITOR"); //应用在清淡文件中注册的action intent.setPackage("com.mirror.mobile"); //应用程序的包名 startService(intent);
第三方的service清单文件注册
<service android:name="com.reeman.two.TestService" android:enabled="true" android:exported="true" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.START_PCM_PLAY_SERVICE" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </service>
其他的逻辑都是一样的 ,
- 启动第三方的Activity,service
- Android-PackageManager与startActivity启动第三方应用的Activity
- 启动第三方非入口activity
- service 启动activity的问题解决
- Activity和Service的启动
- 在第三方浏览器中打开本地app某个activity 使得app多次启动的解决办法
- 提高第三方app的service优先级
- 第三方登录-------activity
- android 启动第三方程序的代码
- android 启动第三方程序的代码
- 启动第三方或系统的应用
- Service如何关闭启动自己的Activity
- Service如何关闭启动自己的Activity
- Activity与Service的启动和绑定
- 如何启动一个没有Activity的Service
- activity启动service的两种方式
- EGL调用第三方Service
- Service 中启动 Activity
- 【数学建模】CUMCM-2013B 碎纸片的拼接复原 解题思路整理
- mybatis 引入映射器的方法
- mybantis 映射器的自动映射和驼峰映射
- BZOJ 1911 [Apio2010]特别行动队 (斜率优化DP)
- 数据结构实验之链表一:顺序建立链表
- 启动第三方的Activity,service
- WireShark如何抓取本地localhost的包
- 计算机如何执行取数指令
- [python]leetcode(79). Word Search
- hibernate错误总结
- mybatis 传递多个参数
- com.opensymphony.xwork2.config.ConfigurationException: Unable to load configuration.
- IAR for 430软件的简单使用
- QT之信号槽(一)