问题
How to make directly show live wallpaper in main activity with android ?
I want one screen ,
Sample:
When I click to program I want to direct Live Wallpaper "Set Wallpaper" live screen:
Sample Look Picture Please ![enter image description here][1]
http://i.stack.imgur.com/IFzTy.png
I don't want wallpaper list,I don't want main activity other button..I want only When I click to program I want to direct Live Wallpaper "Set Wallpaper" live screen.
Sorry , My english is bad..
How can I do? Please help me
I have total 4 java code:
Animationwallpaper.java Bokehrainbowcircle.java Bokehrainbowwallpaper.java MainActivity.Java
And My manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample.livewallpaper.bokehrainbow" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<uses-feature android:name="android.software.live_wallpaper" />
<!-- We need to request a permission to install a shortcut icon -->
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<application
android:label="@string/wallpapers"
android:icon="@drawable/icon">
<service
android:name="com.funnyphotoshoppictures.BokehRainbowWallpaper"
android:permission="android.permission.BIND_WALLPAPER">
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data android:name="android.service.wallpaper" android:resource="@layout/bokeh" />
</service>
<activity
android:name="com.funnyphotoshoppictures.AnimationWallpaper"
android:theme="@android:style/Theme.WallpaperSettings"
android:exported="true">
</activity>
<!-- Register the activity in the manifest -->
<activity
android:name="com.funnyphotoshoppictures.MainActivity"
android:theme="@android:style/Theme.WallpaperSettings"
android:screenOrientation="portrait"
android:icon="@drawable/icon">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<supports-screens
android:smallScreens="false"
android:normalScreens="true"
android:largeScreens="true" />
</manifest>
回答1:
After button is pushed, execute these code. The codes inside "try" means jumping exactly to your targeted live wall paper but not the gallery of all of your live wallpapers. It seems fulfilled your requirement but it just works for >android 4.1.
The codes inside "catch" means jumping to the gallery of all of your live wallpapers if the phone doesn't support the code in "try".
Hopefully, it could help you :)
try{
Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
new ComponentName(MainActivity.this, com.abc.YourMainProgram.class));
startActivity(intent);
}
catch(Exception e){
Intent intent = new Intent();
intent.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
startActivity(intent);
}
回答2:
Use this in your styles.xml:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowShowWallpaper">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
来源:https://stackoverflow.com/questions/23620675/how-to-make-directly-show-live-wallpaper-in-main-activity