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();
0 0