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 .
Asked
Active
Viewed 856 times
-5
-
but this example get package name of that aap only when insatlled or uninstall – Raghvender Kumar Apr 22 '16 at 04:23
-
3already in stack overflow http://stackoverflow.com/questions/36768091/how-to-get-package-name-from-apk-in-android/36768301#36768301 – Sanjay Kakadiya Apr 22 '16 at 04:25
-
yes I want if any app from my list is download get package name of that – Raghvender Kumar Apr 22 '16 at 05:18
-
ok so you need a `BroadcastReceiver` listening for an action `Intent#ACTION_PACKAGE_ADDED` – pskink Apr 22 '16 at 05:19
-
how to add a `BroadcastReceiver`? – pskink Apr 22 '16 at 05:37
-
yes thats what I was asking – Raghvender Kumar Apr 22 '16 at 05:38
-
read [this](http://developer.android.com/guide/components/fundamentals.html#ActivatingComponents) – pskink Apr 22 '16 at 05:40
3 Answers
5
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
PACKAGE_NAME = getApplicationContext().getPackageName();
}

Tony Augustine
- 180
- 5
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