下面列出了android.content.Intent#ACTION_SET_WALLPAPER 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static int getAction(@Nullable Intent intent) {
if (intent == null) return ACTION_DEFAULT;
String action = intent.getAction();
if (action != null) {
switch (action) {
case ACTION_ADW_PICK_ICON:
case ACTION_TURBO_PICK_ICON:
case ACTION_LAWNCHAIR_ICONPACK:
case ACTION_NOVA_LAUNCHER:
case ACTION_ONEPLUS_PICK_ICON:
case ACTION_PLUS_HOME:
return ICON_PICKER;
case Intent.ACTION_PICK:
case Intent.ACTION_GET_CONTENT:
return IMAGE_PICKER;
case Intent.ACTION_SET_WALLPAPER:
return WALLPAPER_PICKER;
default:
return ACTION_DEFAULT;
}
}
return ACTION_DEFAULT;
}
@Override public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_settings:
startActivityForResult(new Intent(this, SettingsActivity.class),
SETTINGS_RETURN_CODE);
return true;
case R.id.action_force_refresh:
recreate();
return true;
case R.id.action_view_widgets:
WidgetsDialogFragment widgetFragment = new WidgetsDialogFragment();
widgetFragment.show(getSupportFragmentManager(), "Widgets Dialog");
return true;
case R.id.update_wallpaper:
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
startActivity(Intent.createChooser(intent, getString(R.string.action_wallpaper)));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public static int getAction(@Nullable Intent intent) {
if (intent == null) return ACTION_DEFAULT;
String action = intent.getAction();
if (action != null) {
switch (action) {
case ACTION_ADW_PICK_ICON:
case ACTION_TURBO_PICK_ICON:
case ACTION_NOVA_LAUNCHER:
case ACTION_PLUS_HOME:
return ICON_PICKER;
case Intent.ACTION_PICK:
case Intent.ACTION_GET_CONTENT:
return IMAGE_PICKER;
case Intent.ACTION_SET_WALLPAPER:
return WALLPAPER_PICKER;
default:
return ACTION_DEFAULT;
}
}
return ACTION_DEFAULT;
}
@Override public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_settings:
startActivityForResult(new Intent(this, SettingsActivity.class),
SETTINGS_RETURN_CODE);
return true;
case R.id.action_force_refresh:
recreate();
return true;
case R.id.action_view_widgets:
WidgetsDialogFragment widgetFragment = new WidgetsDialogFragment();
widgetFragment.show(getSupportFragmentManager(), "Widgets Dialog");
return true;
case R.id.update_wallpaper:
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
startActivity(Intent.createChooser(intent, getString(R.string.action_wallpaper)));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.customization_default_launcher:
dismiss();
mLauncherActivity.startActivity(new Intent("android.settings.HOME_SETTINGS"));
break;
case R.id.customization_wallpaper:
dismiss();
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
mLauncherActivity.startActivityForResult(intent, LauncherActivity.WALLPAPER_SELECT_INTENT_CODE);
break;
case R.id.customization_edit_dock_icons:
dismiss();
mLauncherActivity.startDockIconsEditing();
break;
case R.id.customization_icon_pack:
dismiss();
mLauncherActivity.finish();
mLauncherActivity.startActivity(new Intent(mLauncherActivity, IconPackChooserActivity.class));
break;
}
}
@Override
public void onClick(WallpaperPickerActivity a) {
final ComponentName itemComponentName = new ComponentName(
mResolveInfo.activityInfo.packageName, mResolveInfo.activityInfo.name);
Intent launchIntent = new Intent(Intent.ACTION_SET_WALLPAPER);
launchIntent.setComponent(itemComponentName);
a.startActivityForResultSafely(
launchIntent, WallpaperPickerActivity.PICK_WALLPAPER_THIRD_PARTY_ACTIVITY);
}
@Override
public void onClick(WallpaperPickerActivity a) {
final ComponentName itemComponentName = new ComponentName(
mResolveInfo.activityInfo.packageName, mResolveInfo.activityInfo.name);
Intent launchIntent = new Intent(Intent.ACTION_SET_WALLPAPER);
launchIntent.setComponent(itemComponentName);
a.startActivityForResultSafely(
launchIntent, WallpaperPickerActivity.PICK_WALLPAPER_THIRD_PARTY_ACTIVITY);
}
@Override
public void onClick(WallpaperPickerActivity a) {
final ComponentName itemComponentName = new ComponentName(
mResolveInfo.activityInfo.packageName, mResolveInfo.activityInfo.name);
Intent launchIntent = new Intent(Intent.ACTION_SET_WALLPAPER);
launchIntent.setComponent(itemComponentName);
a.startActivityForResultSafely(
launchIntent, WallpaperPickerActivity.PICK_WALLPAPER_THIRD_PARTY_ACTIVITY);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.action_settings:
final Intent intentSettings = new Intent(this, SettingsActivity.class);
startActivity(intentSettings);
return true;
case R.id.action_refresh_app_list:
recreate();
return true;
case R.id.action_system_settings:
final Intent intentSystemSettings = new Intent(Settings.ACTION_SETTINGS);
intentSystemSettings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentSystemSettings);
return true;
case R.id.action_manage_apps:
final Intent intentManageApps = new Intent(Settings.ACTION_APPLICATION_SETTINGS);
intentManageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentManageApps);
return true;
case R.id.action_set_wallpaper:
final Intent intentWallpaperPicker = new Intent(Intent.ACTION_SET_WALLPAPER);
startActivity(intentWallpaperPicker);
return true;
case R.id.action_about:
final Intent intentAbout = new Intent(this, AboutActivity.class);
startActivity(intentAbout);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void startWallpaper(){
final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Intent chooser = Intent.createChooser(pickWallpaper,"设置壁纸");
startActivity(chooser);
}
public ThirdPartyWallpaperPickerListAdapter(Context context) {
mInflater = LayoutInflater.from(context);
mPackageManager = context.getPackageManager();
mIconSize = context.getResources().getDimensionPixelSize(R.dimen.wallpaperItemIconSize);
final PackageManager pm = mPackageManager;
final Intent pickWallpaperIntent = new Intent(Intent.ACTION_SET_WALLPAPER);
final List<ResolveInfo> apps =
pm.queryIntentActivities(pickWallpaperIntent, 0);
// Get list of image picker intents
Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT);
pickImageIntent.setType("image/*");
final List<ResolveInfo> imagePickerActivities =
pm.queryIntentActivities(pickImageIntent, 0);
final ComponentName[] imageActivities = new ComponentName[imagePickerActivities.size()];
for (int i = 0; i < imagePickerActivities.size(); i++) {
ActivityInfo activityInfo = imagePickerActivities.get(i).activityInfo;
imageActivities[i] = new ComponentName(activityInfo.packageName, activityInfo.name);
}
outerLoop:
for (ResolveInfo info : apps) {
final ComponentName itemComponentName =
new ComponentName(info.activityInfo.packageName, info.activityInfo.name);
final String itemPackageName = itemComponentName.getPackageName();
// Exclude anything from our own package, and the old Launcher,
// and live wallpaper picker
if (itemPackageName.equals(context.getPackageName()) ||
itemPackageName.equals("com.android.launcher") ||
itemPackageName.equals("com.android.wallpaper.livepicker")) {
continue;
}
// Exclude any package that already responds to the image picker intent
for (ResolveInfo imagePickerActivityInfo : imagePickerActivities) {
if (itemPackageName.equals(
imagePickerActivityInfo.activityInfo.packageName)) {
continue outerLoop;
}
}
mThirdPartyWallpaperPickers.add(new ThirdPartyWallpaperTile(info));
}
}
public void startWallpaper() {
final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
pickWallpaper.setComponent(getWallpaperPickerComponent());
startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
}
public ThirdPartyWallpaperPickerListAdapter(Context context) {
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mPackageManager = context.getPackageManager();
mIconSize = context.getResources().getDimensionPixelSize(R.dimen.wallpaperItemIconSize);
final PackageManager pm = mPackageManager;
final Intent pickWallpaperIntent = new Intent(Intent.ACTION_SET_WALLPAPER);
final List<ResolveInfo> apps =
pm.queryIntentActivities(pickWallpaperIntent, 0);
// Get list of image picker intents
Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT);
pickImageIntent.setType("image/*");
final List<ResolveInfo> imagePickerActivities =
pm.queryIntentActivities(pickImageIntent, 0);
final ComponentName[] imageActivities = new ComponentName[imagePickerActivities.size()];
for (int i = 0; i < imagePickerActivities.size(); i++) {
ActivityInfo activityInfo = imagePickerActivities.get(i).activityInfo;
imageActivities[i] = new ComponentName(activityInfo.packageName, activityInfo.name);
}
outerLoop:
for (ResolveInfo info : apps) {
final ComponentName itemComponentName =
new ComponentName(info.activityInfo.packageName, info.activityInfo.name);
final String itemPackageName = itemComponentName.getPackageName();
// Exclude anything from our own package, and the old Launcher,
// and live wallpaper picker
if (itemPackageName.equals(context.getPackageName()) ||
itemPackageName.equals("com.android.launcher") ||
itemPackageName.equals("com.android.wallpaper.livepicker")) {
continue;
}
// Exclude any package that already responds to the image picker intent
for (ResolveInfo imagePickerActivityInfo : imagePickerActivities) {
if (itemPackageName.equals(
imagePickerActivityInfo.activityInfo.packageName)) {
continue outerLoop;
}
}
mThirdPartyWallpaperPickers.add(new ThirdPartyWallpaperTile(info));
}
}
public ThirdPartyWallpaperPickerListAdapter(Context context) {
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mPackageManager = context.getPackageManager();
mIconSize = context.getResources().getDimensionPixelSize(R.dimen.wallpaperItemIconSize);
final PackageManager pm = mPackageManager;
final Intent pickWallpaperIntent = new Intent(Intent.ACTION_SET_WALLPAPER);
final List<ResolveInfo> apps =
pm.queryIntentActivities(pickWallpaperIntent, 0);
// Get list of image picker intents
Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT);
pickImageIntent.setType("image/*");
final List<ResolveInfo> imagePickerActivities =
pm.queryIntentActivities(pickImageIntent, 0);
final ComponentName[] imageActivities = new ComponentName[imagePickerActivities.size()];
for (int i = 0; i < imagePickerActivities.size(); i++) {
ActivityInfo activityInfo = imagePickerActivities.get(i).activityInfo;
imageActivities[i] = new ComponentName(activityInfo.packageName, activityInfo.name);
}
outerLoop:
for (ResolveInfo info : apps) {
final ComponentName itemComponentName =
new ComponentName(info.activityInfo.packageName, info.activityInfo.name);
final String itemPackageName = itemComponentName.getPackageName();
// Exclude anything from our own package, and the old Launcher,
// and live wallpaper picker
if (itemPackageName.equals(context.getPackageName()) ||
itemPackageName.equals("com.android.launcher") ||
itemPackageName.equals("com.android.wallpaper.livepicker")) {
continue;
}
// Exclude any package that already responds to the image picker intent
for (ResolveInfo imagePickerActivityInfo : imagePickerActivities) {
if (itemPackageName.equals(
imagePickerActivityInfo.activityInfo.packageName)) {
continue outerLoop;
}
}
mThirdPartyWallpaperPickers.add(new ThirdPartyWallpaperTile(info));
}
}
/**
* 选择系统壁纸
*
* @param view
*/
public void onSelectSystemWallpaper(View view) {
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
startActivityForResult(Intent.createChooser(intent, "选择壁纸"), REQUEST_CODE_SELECT_SYSTEM_WALLPAPER);
}