how to know android app is installing/downloading - android

I am developing an android app in which user earns points when he installs and runs the apps from play store. Now if user wants to earn pints then he has to install the some apps from play store...while installing the app from play store what is the status of app(installing/downloading)
In my Android app I want to know the status of an app. i.e app is installing or downloading
I found NotifyListenerservice...not sure it is for that only.
Please tell me how to achieve this.
Thanks,
Anjali

Use a BroadcastReceiver to see if it has been installed or removed, or whatever you want.
<receiver
android:name=".receiver.PackageChangeReceiver"
android:enabled="true">
<intent-filter android:priority="99999998">
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_CHANGED"/>
<action android:name="android.intent.action.PACKAGE_FULLY_REMOVED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<data android:scheme="package" />
</intent-filter>
</receiver>
You can find an example here Intent PACKAGE_ADDED not registering
You can also use an AccessibilityService to validate if the app has been started, but you shouldnt abuse this for this use.

No you can't check.. Your app can't be aware of being installed or it is downloaded.
The broadcast receivers will be initialized only after the manual launch of the application. Before that broadcast receivers are not actually listening.
The application is in stopped state. The app needs a manual launch..

#Anjali The problem which you are asking is called Conversion Tracking. You can find out more about this term on Google.
When app is installed on device then OS send a broadcast to the application which can be listen by application. Have a look at below code:
#Override
public void onReceive(Context context, Intent intent) {
try {
if (intent.getAction().equals("com.android.vending.INSTALL_REFERRER")) {
Bundle extras = intent.getExtras();
String referrerString = extras.getString("referrer");
//ReferrerString variable contain your data which was passed to your application. Now you can do whatever you want to like communicating with server etc.
}
} catch (Exception e) {
}
}
Generally, If you are passing some unique parameter in the url to install the application then you will get those parameter in ReferrerString. Your play store link will look something like below:
http://play.google.com/store/apps/details?id=packagename&referrer=yourdata
You would need below manifest entries for it:
<receiver android:name="packagename.BoradcastReciverImplmentedClass" android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>

Related

How to receive broadcast itself when my application updated with new version code android

I have an application which is remotely updated with new version by changing version code. Update is pushed from a back-end side and phone is update the apk using the adb OTA client.
After completion of OTA update I need to send the status to the back-end using the application pro-grammatically.
I can do that using a launcher which is actually receiving the package changed or removed related intent action and then launch the main app. Then the application will send the OTA update status to the back-end without any user interaction.
Here is the Sample code.
In launcher app manifest:
<receiver android:name=".receivers.PackageChangedReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_CHANGED" />
<data android:scheme="package"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Here is the receiver:
#Override
public void onReceive(Context context, Intent intent) {
String packageName=intent.getData().getEncodedSchemeSpecificPart();
if(packageName.contains(context.getString("packagename")))
context.startActivity(new Intent(context, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK));
}
Now my question is how can I do the same things like launch the main app and send OTA update status using the Main Application only without any launcher and user interaction in app after the OTA update?
You can have your own application catch the broadcast Intent, just like the launcher app. Then you can do what you want. Create a BroadcastReceiver in your application and add these entries to the manifest:
<receiver android:name=".MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_CHANGED" />
</intent-filter>
</receiver>
You don't need the <category> or <data> tags and it is pointless to listen for PACKAGE_REMOVED because if your app is removed you won't get triggered anyway.

Install tracking needs to been exported or not?

I am tracking my installs with two methods like you can see here in my manifest:
<receiver
android:name="com.google.android.gms.tagmanager.InstallReferrerReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<receiver
android:name=".tracking.ReferralReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
The second receiver generates a lint warning the first not. Does that mean that Google knows that for their InstallReferrerReceiver and know that it is safe to let it exported?
PS: I know I can use tools:ignore="ExportedReceiver".
The INSTALL_REFERRER intent is broadcasted when an app is installed from the Google Play Store.
android:exported="true" means that the receiver is allowed to receive broadcast intents from other applications. You do want this, or you will not be able to receive the event which is sent by another app (the system or the Play Store app, I'm not sure).
However, if you check the documentation for android:exported, its default value is true if it has at least one <intent-filter>, otherwise it is false.
So to sum up, you need android:exported="true" to catch the event. But omitting this property would be also OK, since the default value is true for your receivers (but it's safer to have it).
About the Lint warning: It recognizes the name, and that's why it knows that the first version is safe.

how to get notified before the new application has installed?

I am making an android app that will check for any vulnerability and malicious detection in android app being installed. now what i want is when user is installing any app then before the app get installed on device i get notified but broadcast receiver so that i can check the app for detection?
i have tried PACKAGE_ADDED but it is notifying me after the app has installed .plz tell me how can i do.i have used this code
<receiver
android:name="MyReceiver"
android:enabled="true"
android:priority="0" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" >
</action>
<action android:name="android.intent.action.PACKAGE_REMOVED" >
</action>
<data android:scheme="package" />
</intent-filter>
</receiver>
The logic in your description is to detect a package that not being installed. Why not to trigger some methods inside the uninstalled package and detect the related reaction, Or reverse the apk to the source code then analysis what you want.
To write an activity which may or may not be a launcher activity:
PackageManager pm = getPackageManager();
Intent appStartIntent = pm.getLaunchIntentForPackage("com.your.broadcast.receiver.package");
if (null!= appStartIntent)
{
startActivity(appStartIntent);
}
Also, you can try intent flag withFLAG_INCLUDE_STOPPED_PACKAGES to access the application that is stopped. Hope this could help you.

I am making an app and want to know when the app is uninstalling

I am making an app and want to know when the app is uninstalling. For doing it, I used BroadcastReceiver but I don't know where is my code is wrong? (when my app is uninstalling, BroadcastReceiver can't receive any message about uninstalling)
It's my app's Manifest:
<receiver android:name="receiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_DATA_CLEARED"/>
<action android:name="android.intent.action.PACKAGE_INSTALL"/>
<action android:name="android.intent.action.UID_REMOVED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<action android:name="android.intent.action.MEDIA_REMOVED"/>
<action android:name="android.intent.action.MEDIA_BAD_REMOVAL"/>
<action android:name="android.intent.action.BATTERY_OKAY"/>
<data android:scheme="com.example.testpermission"/>
</intent-filter>
You cannot get an event when your own app is uninstalling. See here. There is also a post on the subject here.
You can't, but if you have second installed application on the device - you can get notification via that application about the uninstallation of the first one (as far as I remember).
I believe that the application cannot monitor its own uninstall from two reasons:
It will make it much harder to uninstall application (some evil apps might even try to do something bad when their application is being removed).
If you remove application - you cannot run it, or send it events! The app should be closed for clean deletion.
About how to do it from second app:
Your second app should be a receiver to the ACTION_PACKAGE_REMOVED event (read about BroadcastReceiver, and see: http://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_REMOVED)

Android - How to intercept the 'Install application' intent

OK, so not entirely sure this is possible...
But trying to write an application so that I can run some code before any of the following activities are performed.
1) APK is downloaded from web and market launches installer
2) Install button is pressed on android market
Is it possible to intercept and prompt on these events, or has Google locked that stuff down quite tightly?
This isn't an answer per se, but I can't find any commenting tool here. Sorry.
I'm having this issue as well. I would like to be able to detect new application installs. I know it is possible - for example, the app Apps to SD posts a notification when you install a new app that when clicked opens a dialog to move that new app to the sd card.
So far, all I've been able to figure is like this:
manifest.xml:
...
<receiver android:name=".IntentReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
...
IntentReciever.java:
public class IntentReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
context.startService(new Intent(context, YourService.class));
}
}
YourService is then created and calls onCreate() then onStartCommand(). However, I haven't been able to debug this or successfully display any notifications from the service class, so I'm not entirely sure this works. I have gotten this to work for other Receivers like android.intent.action.BOOT_COMPLETED.
Using a BroadcastReceiver you can filter the android.intent.action.PACKAGE_ADDED intent. However this will only be after the two actions you describe, not before. And it will not stop or interrupt the installation.
AFAIK there is no way to do anything before or to interrupt the Market. And then we're even talking about another app than the one that's being installed ofcourse.

Categories

Resources