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

  • 相关阅读:
    NserviceBus+rabbitmq
    c#调用Mysql带参数的存储过程
    datatable list 之前相互转换
    (gridcontrol等)通用导出excel z
    异步数据库查询 Z
    Gridview导出EXCEL(多页) z
    [自制简单操作系统] 4、计时器(线性表实现优化中断)
    [JAVA] 基于TCP的起重机运行模拟器
    [自制简单操作系统] 3、内存管理和窗口叠加
    [自制简单操作系统] 2、鼠标及键盘中断处理事件[PICGDTIDTFIFO]
  • 原文地址:https://www.cnblogs.com/fengzhblog/p/2752150.html
Copyright © 2011-2022 走看看