Question

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?

Was it helpful?

Solution

Found a solution:

  1. 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;}
    
  2. 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)));
    }
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top