How to check if my Live-Wallpaper is running

╄→尐↘猪︶ㄣ 提交于 2019-12-11 16:06:46

问题


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:

  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)));
    }
    


来源:https://stackoverflow.com/questions/21939353/how-to-check-if-my-live-wallpaper-is-running

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!