1、Android判断是Pad或者手机

    public boolean isTabletDevice() {              TelephonyManager telephony = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);              int type = telephony.getPhoneType();              if (type == TelephonyManager.PHONE_TYPE_NONE) {                  return true;              } else {                  return false;              }          }  

2、到android设置中的卸载界面

Uri uri = Uri.fromParts("package", appInfo.packageName, null);       Intent it=new Intent();  it.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");  it.setData(uri);  startActivity(it); 

3、获取屏幕上正在显示的Activity

ActivityManager mActivityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);ComponentName mComponentName = mActivityManager.getRunningTasks(1).get(0).topActivity; 

4、如何判断一个activity是否存在于系统中

    Intent intent = new Intent();      intent.setClassName("包名", "类名");            if(getPackageManager().resolveActivity(intent, 0) == null) {          //说明系统中不存在这个activity      }  

5、如何获取状态栏和标题栏的高度

获取状态栏高度:decorView是window中的最顶层view,可以从window中获取到decorView,然后decorView有个 getWindowVisibleDisplayFrame方法可以获取到程序显示的区域,包括标题栏,但不包括状态栏。于是,我们就可以算出状态栏的高度。Rect frame = new Rect();  getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);  int statusBarHeight = frame.top; 获取标题栏高度: getWindow().findViewById(Window.ID_ANDROID_CONTENT)这个方法获取到的view就是程序不包括标题栏的部分,然后就可以知道标题栏的高度了。     int contentTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();      //statusBarHeight是上面所求的状态栏的高度      int titleBarHeight = contentTop - statusBarHeight;  

6、如何判断快捷方式是否已经创建

 快捷方式信息是保存在com.android.launcher的launcher.db的favorites表中  boolean isInstallShortcut = false ;      final ContentResolver cr = context.getContentResolver();      final String AUTHORITY = "com.android.launcher.settings";      final Uri CONTENT_URI = Uri.parse("content://" +                       AUTHORITY + "/favorites?notify=true");            Cursor c = cr.query(CONTENT_URI,      new String[] {"title","iconResource" },      "title=?",      new String[] {"XXX" }, null);//XXX表示应用名称。              if(c!=null && c.getCount()>0){          isInstallShortcut = true ;      }      /*try {         while (c.moveToNext()) {                                     String tmp = "";             tmp = c.getString(0);         }         } catch (Exception e) {          } finally {             c.close();         }*/      return isInstallShortcut ;  }  

要有权限:
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"/>
注意:2.2及其之后的版本不能用这个方法判断!(虽然在launcher.db数据库里还有favorites这个表)

7、如何在android的一个应用中调用另外一个应用

Intent intent = new Intent();  //第一个参数另一个应用的包名,第二个是需要启动的类  intent.setComponent(new ComponentName("com.Ex03_03","com.Ex03_03.Ex03_03"));  startActivity(intent);

8、如何监测是否静音

    AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);       switch (am.getRingerMode()) {           case AudioManager.RINGER_MODE_SILENT:               Log.i("MyApp","Silent mode");               break;           case AudioManager.RINGER_MODE_VIBRATE:               Log.i("MyApp","Vibrate mode");               break;           case AudioManager.RINGER_MODE_NORMAL:               Log.i("MyApp","Normal mode");               break;       }   

更多相关文章

  1. android中获取当前程序路径
  2. 在android中实现动态跑动的图表实现方法
  3. 【Android ndk-stack tool】用ndk-stack分析应用native程序异常c
  4. 【Android view】获取状态栏高度statu bar height的正确姿势
  5. Android之从Browser中打开本地的应用程序&微信检测是否有对应app
  6. Android service的开启和绑定,以及调用service的方法
  7. Android中JNI的使用方法
  8. 换掉整个程序的bitton样式,以及button的父样式
  9. 【解决方法】Unexpected namespace prefix “xmlns” found for

随机推荐

  1. android BaseAdapter 自定义适配器 BaseA
  2. android 推送
  3. Android:关于string.xml中的字符串特殊格
  4. android 百度地图3.0
  5. android之activities的生命周期
  6. android 判断当前是否是飞行模式和侦听ai
  7. Android(安卓)RenderScript 实现 LowPoly
  8. 2.4.3 日期/时间选择器
  9. android ViewPaper高度自适应
  10. Android之动画PopupWindow