-5

I am devloping an app that contain list of app ,what I have to do is when user click on particular app he will be redirected to google play store and after successful download of that app I have to get package name of that app for this I am using broadcast receiver.But this receiver get package name of every app whenever new app is download in device .But I only want to get package name of that app which is listed in my app .

mdDroid
  • 3,135
  • 2
  • 22
  • 34
Raghvender Kumar
  • 143
  • 3
  • 11

3 Answers3

5
    @Override 
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    PACKAGE_NAME = getApplicationContext().getPackageName();
}
1
    List<ApplicationInfo> packages;
    PackageManager pm;
    pm = getPackageManager();

    //get a list of installed apps.
    packages = pm.getInstalledApplications(0);

    ActivityManager mActivityManager = (ActivityManager) context
            .getSystemService(Context.ACTIVITY_SERVICE);

    for (ApplicationInfo packageInfo : packages) {

        PAKAGE_NAME = packageInfo.packageName contains package name

    }
ErShani
  • 392
  • 2
  • 9
0

Use getPackageManager().getPackageInfo(getPackageName(), 0).packageName

You can also create a function for this:

public String getPackageName(Context context) {
    return context.getPackageName();
}
mdDroid
  • 3,135
  • 2
  • 22
  • 34
  • but this will give my app package name only,I want whenever particular app is successful downloded get that package name ,try to understand – Raghvender Kumar Apr 22 '16 at 04:43