android 关于包的用法
来源:互联网 发布:linux域名绑定ip 编辑:程序博客网 时间:2024/05/16 17:21
Intent intent=getIntent();
ComponentName cn=intent.getComponent();
String packname=cn.getPackageName();
String clsname=cn.getClassName();
对于一个activity ,可以从intent获得其组件名,再从组件名获得包名,是主包名吗? 不是吧? 再从包名获得类名。
Intent mainIntent = new Intent(Intent.ACTION_MAIN,null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
/*getInstalledApplications 返回当前设备上安装的应用包集合
* ApplicationInfo对应着androidManifest.xml中的application标签。通过它可以获取该application对应的信息
*/
List<ApplicationInfo> applicationInfos = this.getPackageManager().getInstalledApplications(0);
HashMap<String, String> resultMap = new HashMap<String, String>();
Iterator<ApplicationInfo> iterator = applicationInfos.iterator();
while(iterator.hasNext())
{
ApplicationInfo applicationInfo=iterator.next();
String packageName = applicationInfo.packageName;// 包名
String packageLabel = this.getPackageManager().getApplicationLabel(applicationInfo).toString();//获取label
resultMap.put(packageName, packageLabel);
}
//PackageManager pm = getPackageManager();
//List<ResolveInfo> activities = pm.queryIntentActivities(
// new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); 通过intent查询activity ,查到的ResolveInfo到底是什么?
handler.post(new Runnable()的作用:
handler.post(new Runnable(){
//post传输一个runnable对象给消息队列,并在到达消息队列后被调用,这个方法不仅用于弹出框,还可以用于其他界面UI元素的更新。
public void run() {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "启动服务", 例如:textview.set(null);刷掉残留的字符等。
Toast.LENGTH_LONG).show();
}});
//关于android系统函数的调用:ServiceManager 类的getService(String name)方法
Method method=Class.forName("android.os.ServiceManager").getMethod("getService", String.class);
//getService 方法是静态的 所以第一个参数是null
IBinder binder=(IBinder)method.invoke(null, new Object[]{TELEPHONY_SERVICE });
//Android没有对外公开结束通话的API,如果需要结束通话,必须使用AIDL与电话管理服务进行通信, 并调用服务中的API实现结束通话
//从Android的源代码中拷贝以下文件到项目中:
//com/android/internal/telephony/ITelephony.aidl
//android/telephony/NeighboringCellInfo.aidl
//开发工具会在gen目录下自动生成ITelephony.java
//ITelephony telephony = ITelephony.Stub.asInterface(binder);
//调用ITelephony.endCall()结束通话
//telephony.endCall();
ComponentName cn=intent.getComponent();
String packname=cn.getPackageName();
String clsname=cn.getClassName();
对于一个activity ,可以从intent获得其组件名,再从组件名获得包名,是主包名吗? 不是吧? 再从包名获得类名。
Intent mainIntent = new Intent(Intent.ACTION_MAIN,null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
/*getInstalledApplications 返回当前设备上安装的应用包集合
* ApplicationInfo对应着androidManifest.xml中的application标签。通过它可以获取该application对应的信息
*/
List<ApplicationInfo> applicationInfos = this.getPackageManager().getInstalledApplications(0);
HashMap<String, String> resultMap = new HashMap<String, String>();
Iterator<ApplicationInfo> iterator = applicationInfos.iterator();
while(iterator.hasNext())
{
ApplicationInfo applicationInfo=iterator.next();
String packageName = applicationInfo.packageName;// 包名
String packageLabel = this.getPackageManager().getApplicationLabel(applicationInfo).toString();//获取label
resultMap.put(packageName, packageLabel);
}
//PackageManager pm = getPackageManager();
//List<ResolveInfo> activities = pm.queryIntentActivities(
// new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); 通过intent查询activity ,查到的ResolveInfo到底是什么?
handler.post(new Runnable()的作用:
handler.post(new Runnable(){
//post传输一个runnable对象给消息队列,并在到达消息队列后被调用,这个方法不仅用于弹出框,还可以用于其他界面UI元素的更新。
public void run() {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "启动服务", 例如:textview.set(null);刷掉残留的字符等。
Toast.LENGTH_LONG).show();
}});
//关于android系统函数的调用:ServiceManager 类的getService(String name)方法
Method method=Class.forName("android.os.ServiceManager").getMethod("getService", String.class);
//getService 方法是静态的 所以第一个参数是null
IBinder binder=(IBinder)method.invoke(null, new Object[]{TELEPHONY_SERVICE });
//Android没有对外公开结束通话的API,如果需要结束通话,必须使用AIDL与电话管理服务进行通信, 并调用服务中的API实现结束通话
//从Android的源代码中拷贝以下文件到项目中:
//com/android/internal/telephony/ITelephony.aidl
//android/telephony/NeighboringCellInfo.aidl
//开发工具会在gen目录下自动生成ITelephony.java
//ITelephony telephony = ITelephony.Stub.asInterface(binder);
//调用ITelephony.endCall()结束通话
//telephony.endCall();
0 0
- android 关于包的用法
- 关于Javax.imageIO包的用法
- 关于Android Menu 的用法
- 关于android GridView的用法
- 关于Android Handle的用法
- 关于Android的PopupWindow用法
- 关于Android webView的用法
- Android关于sharedPreferences的用法
- 关于Android LayoutInflater的用法
- android 关于生成jar包的问题
- 关于Android JAR包的优化问题
- 关于android support v7包的使用
- 关于android.widget包的理解
- 关于Android引用包冲突的问题。
- 关于Android网络抓包的工具
- 关于android appcompat_v7包的问题
- 关于android studio的jar包冲突
- android关于provider包冲突的问题
- codeforces 408B Garland
- telnet 实验总结
- 【面向对象常见面试题】访问声明的几点说明(xx)
- 点到直线的距离opencv实现
- 设计模式之——工厂三姐妹
- android 关于包的用法
- 逆波兰表达式学习
- 手机再也不能给孩子玩了,太可怕了!
- 过去,回不去了
- 淡淡
- SybaseIQ - 建库、建表、启动
- direct x264编译中16字节对齐修改
- 算法思考---------八枚银币
- 经典语录-2014330