Skip to content

Instantly share code, notes, and snippets.

@long-nguyen
Created January 30, 2014 02:37
Show Gist options
  • Save long-nguyen/8701601 to your computer and use it in GitHub Desktop.
Save long-nguyen/8701601 to your computer and use it in GitHub Desktop.
@SuppressLint("InlinedApi")
public static void launchApp(final String packageName,final String activityName,final String key,final String value){
if(packageName==null||activityName==null) return ;
UnityPlayer.currentActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
try{
final PackageManager pm = UnityPlayer.currentActivity.getPackageManager();
Intent launchIntent = pm.getLaunchIntentForPackage(packageName);
if(launchIntent!=null){
launchIntent.putExtra(key, value);
UnityPlayer.currentActivity.startActivity(launchIntent);
return;
}
}catch(Exception e){}
//Otherwise open google play
UnityPlayer.currentActivity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+packageName)));
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment