.修改android选择壁纸来源列表

 在主界面按菜单键会弹出菜单,其中有一项是壁纸, 当选择之后,出现一个选择器,出现一个列表,这个不是dialog , 你可以选择是一般的壁纸,还是比较炫的动态壁纸或者是从设备中寻找存在的照片设置为你的桌面壁纸。 startWallpaper  方法,看一下源码
private void startWallpaper() {  
        closeAllApps(true);  
        final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);  
        Intent chooser = Intent.createChooser(pickWallpaper,  
                getText(R.string.chooser_wallpaper));  
        // NOTE: Adds a configure option to the chooser if the wallpaper supports it  
        //       Removed in Eclair MR1  
//        WallpaperManager wm = (WallpaperManager)  
//                getSystemService(Context.WALLPAPER_SERVICE);  
//        WallpaperInfo wi = wm.getWallpaperInfo();  
//        if (wi != null && wi.getSettingsActivity() != null) {  
//            LabeledIntent li = new LabeledIntent(getPackageName(),  
//                    R.string.configure_wallpaper, 0);  
//            li.setClassName(wi.getPackageName(), wi.getSettingsActivity());  
//            chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });  
//        }  
        startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);  
    }  

其实是根据 Intent 调用相关的 Activity。 
final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);  
  
Intent chooser = Intent.createChooser(pickWallpaper,  
                getText(R.string.chooser_wallpaper));  


Intent.ACTION_SET_WALLPAPER 表示的含义以及它的真实值  查看api
public static final String ACTION_SET_WALLPAPER  
Since: API Level 1  
Activity Action: Show settings for choosing wallpaper  
Input: Nothing.  
Output: Nothing.  
Constant Value: "android.intent.action.SET_WALLPAPER" 
该 Intent 常量是一个 String,表示启用设置壁纸的 Activity,也就是说只要我们的系统中有这样的 Activity(action 为  android.intent.action.SET_WALLPAPER )就可以出现在选择器中。 
原生的 android 系统中有三个这样的 Activity 

1.WallpaperChooser.java


这是 Launcher 中的一个类,主要是选择壁纸的操作,和 Launcher.java 在一个包下面。通过 Launcher 的 Manifest.xml 文件就可以看到答案

</activity>  

<activity android:name="com.android.launcher2.WallpaperChooser" android:label="@string/pick_wallpaper" android:icon="@drawable/ic_launcher_wallpaper" android:screenOrientation="nosensor" android:finishOnCloseSystemDialogs="true">  

<intent-filter>  

<action android:name="android.intent.action.SET_WALLPAPER"/>  

<category android:name="android.intent.category.DEFAULT"/>  

</intent-filter>  

</activity>  

2..LiveWallpaperListActivity.java

位于 /packages/wallpapers/LivePicker/src/com/android/wallpaper/livepicker 下面,主要是选择动态壁纸。其 Manifest.xml 文件: 

<activity android:name="LiveWallpaperListActivity"  

            android:icon="@drawable/ic_launcher_live_wallpaper"  

            android:label="@string/live_wallpaper_picker_title"  

            android:theme="@android:style/Theme.NoTitleBar"  

            android:screenOrientation="nosensor">  

            <intent-filter>  

                <action android:name="android.service.wallpaper.LIVE_WALLPAPER_CHOOSER" />  

                <action android:name="android.intent.action.SET_WALLPAPER" />  

                <category android:name="android.intent.category.DEFAULT" />  

            </intent-filter>  

        </activity>  



3.Photographs.java


在以前的版本中,android 使用的是Gallery,现在改变为Gallery3D,位于/packages/apps/Gallery3D/src/com/cooliris/media,对应的 Manifest.xml 文件可自行查阅。

至此就明白了壁纸选择的原理

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值