我想檢查第三方應用程序是否已經啟動。
如果我知道 packagename 的話,就能打開第三方應用程序。
比如:
Intent intent = getPackageManager().getLaunchIntentForPackage("com.thirdparty.package");
startActivity( intent );
我能檢查看它以前是否打開了嗎?如何實現?
public static boolean isServiceStarted(Context context,String PackageName)
{
boolean isStarted =false;
try
{
ActivityManager mActivityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
int intGetTastCounter = 1000;
List<ActivityManager.RunningServiceInfo> mRunningService =
mActivityManager.getRunningServices(intGetTastCounter );
for (ActivityManager.RunningServiceInfo amService : mRunningService)
{
if(0 == amService.service.getPackageName().compareTo(PackageName))
{
isStarted = true;
break;
}
}
}
catch(SecurityException e)
{
e.printStackTrace();
}
return isStarted;
}
權限: