@SuppressLint
(
"NewApi"
)
private
void
launch3rdApp(String packageName) {
Intent mainIntent =
new
Intent(Intent.ACTION_MAIN,
null
);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
PackageManager pm = getActivity().getPackageManager();
List<ResolveInfo> installedApps = pm.queryIntentActivities(mainIntent,
0
);
boolean
installed =
false
;
for
(ResolveInfo resolveInfo : installedApps) {
if
(resolveInfo.activityInfo.packageName.equals(packageName)) {
installed =
true
;
break
;
}
}
if
(installed) {
if
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
final
ActivityManager activityManager = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
final
List<RecentTaskInfo> recentTasks = activityManager.getRecentTasks(Integer.MAX_VALUE, ActivityManager.RECENT_IGNORE_UNAVAILABLE);
RecentTaskInfo recentTaskInfo =
null
;
for
(
int
i =
0
; i < recentTasks.size(); i++)
{
if
(recentTasks.get(i).baseIntent.getComponent().getPackageName().equals(packageName)) {
recentTaskInfo = recentTasks.get(i);
break
;
}
}
if
(recentTaskInfo !=
null
&& recentTaskInfo.id > -
1
) {
activityManager.moveTaskToFront(recentTaskInfo.persistentId, ActivityManager.MOVE_TASK_WITH_HOME);
return
;
}
}
Intent intent = getActivity().getPackageManager().getLaunchIntentForPackage(packageName);
if
(intent !=
null
) {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
else
{
callback.showActionView(PLAY_STORE + packageName);
}
}