Android开发中常用到方法总结 第3页

am is = conn.getInputStream();
   bitmap = BitmapFactory.decodeStream(is);
   is.close();
  } catch (IOException e) {
   e.printStackTrace();
  }
  return bitmap;
 }

10.隐藏app
 public static void HiddenApp(Context ctx) {
  PackageManager pm = ctx.getPackageManager();
  ResolveInfo homeInfo = pm.resolveActivity(
    new Intent(Intent.ACTION_MAIN)
      .addCategory(Intent.CATEGORY_HOME), 0);
  ActivityInfo ai = homeInfo.activityInfo;
  Intent startIntent = new Intent(Intent.ACTION_MAIN);
  startIntent.addCategory(Intent.CATEGORY_LAUNCHER);
  startIntent.setComponent(new ComponentName(ai.packageName, ai.name));
  ctx.startActivity(startIntent);
 }

11.退出程序(3种方法)
 public static void ExitApp(Context ctx) {


  ActivityManager am = (ActivityManager)
  ctx.getSystemService(Context.ACTIVITY_SERVICE);
  am.restartPackage(ctx.getPackageName());
 
  Intent startMain = new Intent(Intent.ACTION_MAIN);
  startMain.addCategory(Intent.CATEGORY_HOME);
  startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  ctx.startActivity(startMain);
  android.os.Process.killProcess(android.os.Process.myPid());
  System.exit(0);
 
  android.os.Process.killProcess(android.os.Process.myPid());
 }

12.查询手机中所有非系统应用

 

 public static List<PackageInfo> getAllApps(Context context) {

 List<PackageInfo> apps = new ArrayList<PackageInfo>();

 PackageManager pManager = context.getPackageManager();

 //获取手机内所有应用

 List<PackageInfo> paklist = pManager.getInstalledPackages(0);

 for (int i = 0; i < paklist.size(); i++) {

 PackageInfo pak = (PackageInfo) paklist.get(i);

 //判断是否为非系统预装的应用程序

 if ((pak.applicationInfo.flags & pak.applicationInfo.FLAG_SYSTEM) <= 0) {

 // customs applications

 apps.add(pak);

 }

 }

 return apps;

 }

 13.查询手机内所有支持分享的应用


 public static List<ResolveInfo> getShareApps(Context context)
 {
  List<ResolveInfo> mApps = new ArrayList<ResolveInfo>();
  Intent intent = new Intent(Intent.ACTION_SEND, null);
  intent.addCategory(Intent.CATEGORY_DEFAULT);
  intent.setType("text/plain");
  PackageManager pManager = context.getPackageManager();
  mApps = pManager
    .queryIntentActivities(intent, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
  return mApps;
 }

 14.获取 Andorid 手机WIFI连接的Mac地址和IP地址

  public static String getInfo()

    {

&n

上一页  [1] [2] [3] [4] [5] 下一页

Copyright © 2007-2012 www.chuibin.com 六维论文网 版权所有