Reputation: 27
I am developing an app which contain list of app, when user click of particular app from list shown to him he will directed to website from which he can download that app to listen app is successfully download I add a broadcast receiver in android menifest.xml.The problem is that broadcast receiver listen if any app downloaded in system as well as from my app also.what I want broadcast receiver should listen only events from app only when my app is open as well as closed.
here is my java code:-
public class Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Check if the application is install or uninstall and display the message accordingly
if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) {
// Application Install
Log.e("Package Added:-", intent.getData().toString());
} else if (intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")) {
Log.e("Package Removed:-", intent.getData().toString());
} else if (intent.getAction().equals("android.intent.action.PACKAGE_REPLACED")) {
Log.e("Package Replaced:-", intent.getData().toString());
}
}
}
here is my xml code:-
<receiver android:name=".Receiver">
<intent-filter android:priority="100">
<action android:name="android.intent.action.PACKAGE_INSTALL"/>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
kinldy help me I am trying from a week plsss.
Upvotes: 0
Views: 1970
Reputation: 38595
There is no way for you to know whether the package is installed by your app just with the information in the Intent
received by your BroadcastReceiver
. Technically, your app isn't installing anything, the system does that (third party apps do not have the privilege to install other apps).
You will have to check the package name from the Intent
data and compare it to apps the user downloaded with your app. That's the best you can do.
Upvotes: 2