如何移动从应用程序动态壁纸preVIEW? [英] How do I move to Live Wallpaper preview from app?
问题描述
我一直在到处找这样一个具体的例子,不能在网上找到的任何地方。
I've been looking all over for a specific example of this and couldn't find it online anywhere.
我想要做的就是:我的应用程序,点击一个按钮,并移动到我的应用程序的动态壁纸preVIEW动态壁纸,让用户可以选择将其激活。
What I want to do is: From my app click a button and move to the Live Wallpaper preview of my apps live wallpaper, so the user can choose to activate it.
现在的我已经在网上看了,我用<一个href="http://developer.android.com/reference/android/app/WallpaperManager.html">WallpaperManager's ACTION_CHANGE_LIVE_WALLPAPER与EXTRA_LIVE_WALLPAPER_COMPONENT指着我LiveWallpapers组件名称。
Now of what I've read online, I'm to use WallpaperManager's ACTION_CHANGE_LIVE_WALLPAPER with EXTRA_LIVE_WALLPAPER_COMPONENT pointing to my LiveWallpapers ComponentName.
下面是一个什么样我到目前为止我的code。任何人都知道我在做什么错了?截至目前我按一下按钮,没有任何反应......(我记录它,它实际上是实现这一code)。
Here's my code of what I have so far. Anybody know what I'm doing wrong? As of now I click the button and nothing happens... (I logged it and it's actually reaching this code).
Intent i = new Intent();
i.setAction(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
i.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, "com.example.myapp.livewallpaper.LiveWallpaperService");
startActivity(i);
如果您需要任何更多的信息,我忘了后让我知道。
If you need any more info that I forgot to post let me know.
*我也知道这是API 16+,这只是我的情况的时候,手机是API 16 +
*I am also aware this is API 16+, this is just my case for when the phone is API 16+
推荐答案
我找不到一个例子无论是。我注意到的第一件事是, EXTRA_LIVE_WALLPAPER_COMPONENT
不需要一个字符串,但组件名
。我先用组件名
切割是这样的:
I couldn't find an example either. The first thing I noticed was that the EXTRA_LIVE_WALLPAPER_COMPONENT
doesn't require a String, but a ComponentName
. My first cut with ComponentName
looked like this:
ComponentName component = new ComponentName(getPackageName(), "LiveWallpaperService");
intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, component);
startActivityForResult(intent, REQUEST_SET_LIVE_WALLPAPER);
这并没有削减它,所以我挖成Android源$ C $ C,发现以下 LiveWallpaperChange.java
:
That didn't cut it, so I dug into the Android source code and found the following in LiveWallpaperChange.java
:
Intent queryIntent = new Intent(WallpaperService.SERVICE_INTERFACE);
queryIntent.setPackage(comp.getPackageName());
List<ResolveInfo> list = getPackageManager().queryIntentServices( queryIntent, PackageManager.GET_META_DATA);
一个小调试上述块,这是我的最终形式......
A little debugging with the above chunk, and this is my final form...
ComponentName component = new ComponentName(getPackageName(), getPackageName() + ".LiveWallpaperService");
intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, component);
startActivityForResult(intent, REQUEST_SET_LIVE_WALLPAPER);
关键的是在第二个参数组件名
。
从技术上讲,我的最终形式支持新方法的等级第一,其次是旧的,随后的Nook平板电脑/ Nook Color的具体意图:
Technically, my final form supports a hierarchy of the new method first, followed by the old, followed by the Nook Tablet/Nook Color specific intent:
Intent intent;
// try the new Jelly Bean direct android wallpaper chooser first
try {
ComponentName component = new ComponentName(getPackageName(), getPackageName() + ".LiveWallpaperService");
intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, component);
startActivityForResult(intent, REQUEST_SET_LIVE_WALLPAPER);
}
catch (android.content.ActivityNotFoundException e3) {
// try the generic android wallpaper chooser next
try {
intent = new Intent(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
startActivityForResult(intent, REQUEST_SET_LIVE_WALLPAPER);
}
catch (android.content.ActivityNotFoundException e2) {
// that failed, let's try the nook intent
try {
intent = new Intent();
intent.setAction("com.bn.nook.CHANGE_WALLPAPER");
startActivity(intent);
}
catch (android.content.ActivityNotFoundException e) {
// everything failed, let's notify the user
showDialog(DIALOG_NO_WALLPAPER_PICKER);
}
}
}
这篇关于如何移动从应用程序动态壁纸preVIEW?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!