zoukankan      html  css  js  c++  java
  • Home例子研究2

    1. 在Home.onCreateOptionsMenu方法中

    // 添加三个菜单项 其中系统设置android.provider.Settings.ACTION_SETTINGS

    menu.add(0, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper).setIcon(android.R.drawable.ic_menu_gallery)
            .setAlphabeticShortcut('W');
    menu.add(0, MENU_SEARCH, 0, R.string.menu_search).setIcon(android.R.drawable.ic_search_category_default)
            .setAlphabeticShortcut(SearchManager.MENU_KEY);
    menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings).setIcon(android.R.drawable.ic_menu_preferences)
            .setIntent(new Intent(android.provider.Settings.ACTION_SETTINGS));

    2. 在Home.onOptionsItemSelected方法中

    item.getItemId() 如果等于MENU_WALLPAPER_SETTINGS 调用方法 startWallpaper 如果等于MENU_SEARCH 调用方法onSearchRequested

    3. 在Home.startWallpaper方法中

    final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
    startActivity(Intent.createChooser(pickWallpaper, getString(R.string.menu_wallpaper)));

    4. 程序运行日志 表示bindFavorites方法执行失败

    11-03 08:09:05.335: ERROR/Home(6880): Couldn't find or open favorites file /system/etc/favorites.xml

    5. 在Home.bindFavorites方法中

    // 创建File对象和FileReader对象

    // Environment.getRootDirectory() 即 /system 或 ANDROID_ROOT

    final File favFile = new File(Environment.getRootDirectory(), DEFAULT_FAVORITES_PATH);

    FileReader favReader = new FileReader(favFile);

    // 创建intent对象和获取packageManager对象

    final Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    final PackageManager packageManager = getPackageManager();

    // 创建XmpPullParser对象 设置输入来自favReader

    final XmlPullParser parser = Xml.newPullParser();
    parser.setInput(favReader);

    // 开始文档解析

    beginDocument(parser, TAG_FAVORITES);

    // 对于每个元素

    nextElement(parser);

    // 获取包名和类名

    final String favoritePackage = parser.getAttributeValue(null, TAG_PACKAGE);
    final String favoriteClass = parser.getAttributeValue(null, TAG_CLASS);

    // 创建ComponentName对象 设置intent属性

    final ComponentName cn = new ComponentName(favoritePackage, favoriteClass);
    intent.setComponent(cn);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    // 获取ApplicationInfo对象

    info = getApplicationInfo(packageManager, intent);

    // 将ApplicationInfo对象添加到列表中

    info.intent = intent;
    mFavorites.addFirst(info);

  • 相关阅读:
    基于 WebGL 的 HTML5 楼宇自控 3D 可视化监控
    基于 HTML5 的 WebGL 楼宇自控 3D 可视化监控
    基于 WebGL 3D 的 HTML5 档案馆可视化管理系统
    基于 HTML5 的 WebGL 3D 档案馆可视化管理系统
    基于 HTML5 的 WebGL 和 VR 技术的 3D 机房数据中心可视化
    代码管理(四)SVN和Git对比
    代码管理(二)sourcetree 安装与使用
    代码管理(一)git
    iOS11新特性之LargeTitle
    使用Cordova搭建Andoid和iOS开发环境
  • 原文地址:https://www.cnblogs.com/fengzhblog/p/2752150.html
Copyright © 2011-2022 走看看