问题
I have a Live Wallpaper and an Activity. How can I check in the Activity if the User activated my Wallpaper and how can I send him to the Live Wallpaper Settings if not?
回答1:
Found a solution:
Method for checking if Service is running
private boolean isMyServiceRunning(String className) { ActivityManager manager = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE); for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (className.equals(service.service.getClassName())) { return true; } } return false;}
Start Intent ACTION_SET_WALLPAPER
//Check if Wallpaper Service is active if(isMyServiceRunning(MyWallpaperService.class.getName())){ Log.d(TAG, "active" ); } else { Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER); startActivity(Intent.createChooser(intent, getActivity().getString(R.string.title_for_wallpaper_chooser))); }
来源:https://stackoverflow.com/questions/21939353/how-to-check-if-my-live-wallpaper-is-running