Created
August 7, 2017 13:16
-
-
Save Binary-Finery/156b19b92803fd008f78136a2794b460 to your computer and use it in GitHub Desktop.
using package manager to launch an installed app on button press
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package spencerstudios.com.project1000_fx; | |
import android.content.ActivityNotFoundException; | |
import android.content.Intent; | |
import android.content.pm.PackageManager; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.widget.Button; | |
public class LauncherActivity extends AppCompatActivity { | |
private Button btn; | |
private int index = 0; | |
//populate this array with your package names.... | |
private final String[] packages = {"com.facebook.katana", "com.facebook,orca"}; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_launcher); | |
btn = (Button) findViewById(R.id.open_app_buttom); | |
btn.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
//lets pretend this is inside your onMenuSelected... | |
Intent intent = getPackageManager().getLaunchIntentForPackage(packages[index]); | |
startActivity(intent); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is helped me!!. Thank you so much TheSevenSeasOfBinary