简体   繁体   English

如何检查我的动态壁纸是否正在运行

[英]How to check if my Live-Wallpaper is running

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? 如果用户激活了我的墙纸,我该如何检入活动;如果未激活,如何将他发送到动态墙纸设置?

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 启动意图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))); } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM