Android referral not firing the BroadCast Receiver - android

I wrote an app that has the following BroadcastReceiver :
<receiver
android:exported="true"
android:name="com.package.InstallReferrerReceiver" >
<intent-filter >
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
The intent fires fine when I am using
am broadcast -a com.android.vending.INSTALL_REFERRER
-n com.example.gatestapp/com.google.analytics.tracking.android.CampaignTrackingReceiver
--es "referrer" "utm_source=testSource&utm_medium=testMedium&utm_term=testTerm&utm_content=testContent&utm_campaign=testCampaign"
But, on uploading this app as a Beta version, it doesnt seem to fire (in the receiver,it should contact a webservice).
I made the link and sent it to people in messages.They opened the referral links in the browser.
What could the problem be ? Is it that it wont work for Beta? or , is there any 'correct' way of downloading from the play store via play ?

Related

Sending an intent in the Android emulator

I have a flutter app. I've declared an intent filter in AndroidManifest.xml like this:
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="test" android:host="test.example.com"/>
</intent-filter>
(I'm not using test.example.com but a domain I actually control.)
I've then set up a web server which serves links like https://test.example.com/?token=xyz into HTTP 301 redirects to test://test.example.com/?token=xyz. The idea is that I'll send a user an email with the first link, which will result in a redirect to an intent which my app receives and this is how the app gets authenticated with my web service.
This all works when I test it on a real Android phone. But when I'm running it in the Android emulator running a Pixel XL API 31 ROM, I can't figure out how to send the intent directly. I'm trying this:
$ adb -e shell
emulator64_x86_64_arm64:/ $ am broadcast -a android.intent.action.VIEW -c android.intent.category.DEFAULT -c android.intent.category.BROWSABLE test://test.example.com/?token=xyz
Broadcasting: Intent { act=android.intent.action.VIEW cat=[android.intent.category.DEFAULT,android.intent.category.BROWSABLE] dat=test://test.example.com/ flg=0x400000 }
Broadcast completed: result=0
This looks successful but nothing happens. As far as I can tell, the app doesn't catch the intent. Am I doing something wrong?

Google Analytics V4 Campaign measurement Testing is not working

I started to Implement Campaign Measurement with Google Analytics V4 referring the link
https://developers.google.com/analytics/devguides/collection/android/v4/ .
Facing an issue when Tested Campign Measurement as mentioned in https://developers.google.com/analytics/solutions/testing-play-campaigns. Every time my logs showing "No Campaign data found"
I imported google Play services (Rev :18) in to my workspace and referred it in my project
Added below lines in my Manifest file
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data android:name="com.google.android.gms.analytics.globalConfigResource"
android:resource="#xml/global_tracker" />
and also below code
<service android:name="com.google.android.gms.analytics.CampaignTrackingService"/>
<receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
later created global_tracker.xml file under res->xml. Below is my xml file
<?xml version="1.0" encoding="utf-8" ?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:ignore="TypographyDashes"
>
<integer name="ga_sessionTimeout">300</integer>
<!-- Enable automatic Activity measurement -->
<bool name="ga_autoActivityTracking">true</bool>
<bool name="ga_debug">true</bool>
<string name="ga_logLevel">verbose</string>
<string name="ga_dryrun">true</string>
<!-- The screen names that will appear in reports -->
<!-- The following value should be replaced with correct property id. -->
<string name="ga_trackingId">UA-xxxxxxx-1</string>
</resources>
replaced Tracking Id with my tracking id
while testing campaign measurement, i first installed my app on to my device (Moto G (4.4.2)) through adb install. Made sure the app is not running and broadcasted the intent as mentioned in the above Link . i got success log when broadcasted the intent.
Intent
E:\xxxxxxx\adt-bundle-windows-x86_64-20140321\sdk\platform-tools
>adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n <My Package name>/com.google.android.gms.analytics.CampaignTrackingReceiver --es "referrer" "utm_source=testsource"
Response:
Broadcasting: Intent { act=com.android.vending.INSTALL_REFERRER cmp=<My Package name>
>/com.google.android.gms.analytics.CampaignTrackingReceiver (has extras) }
Broadcast completed: result=0
When i opened my application i always got " I/GAV2(7342): Thread[GAThread,5,main]: No campaign data found." error in my logs.
Can please someone let me know why am i not getting Campaign data ? where i am going wrong.
Also, why it is Showing "GAV2" in logs when i am using GAV4
GA Logs:
07-09 12:59:26.542: W/GAV2(20502): Thread[main,5,main]: Need to call initialize() and be in fallback mode to start dispatch.
07-09 12:59:31.568: I/GAV2(20502): Thread[GAThread,5,main]: No campaign data found.
Note: This is the first time i am working with Google Analytics. As i want to check whether i am receiving Campaign data or not first, i didn't implemented any trackers to GA
Edit : When i manually trigger the Broadcast intent on button click in my App. I am able to see "Campaign found" log when i restarted my app. But the same not happening when triggered intent using "adb shell" command as mentioned above. I doubt may be intent is not reaching to my device . Is there any way to find whether the intent is received or not ?
Please help
1> ok for the starters you are mixing two things.
this link is for Google Analytics-v4 https://developers.google.com/analytics/devguides/collection/android/v4/
and this link https://developers.google.com/analytics/solutions/testing-play-campaigns is not for v4( the page is too old, there was no GAV4 when this page was published.
2> Check the physical-device(Google play services) version and update it to 5.0, if not already done.
3> you dont need the boiler plate code mentioned below. I think this is for GAV3 and not GAV4
<service android:name="com.google.android.gms.analytics.CampaignTrackingService"/>
<receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
for more clarity on code check this link. No campaign data found. Using Google Analytics v4
4> Specifically for GAV4(with my own exprience), its ok to see the error "No Campaign data found". try to run the code in verbose mode and you will see that GAV4 is making connections to its host.
GoogleAnalytics.getInstance(this).getLogger().setLogLevel(LogLevel.VERBOSE);
5> Do not turn on the dry_run, you will not see the data on Google Analytics. By default this is off.
6> finally, inside Google Analytics see under "Real-time" for live hits.
hope this helps.
I was having the same issue with an extra error of ClassNotFound sometimes.
First i suggest to see Nishant's response and here are a couple more thing to check if they solve your problem:
1) If you are having more than one BroadcastReceiver:
1.1) Ensure you don't! Keep only one and add the intent-filter to that one:
<service android:name="com.google.android.gms.analytics.CampaignTrackingService"/>
<receiver android:name="com.example.MyScheduleReceiver"
android:exported="true">
<intent-filter >
<action android:name="android.intent.action.ACTION_USER_PRESENT" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE"/>
<action android:name="android.intent.action.ACTION_SCREEN_OFF" />
<action android:name="android.intent.action.ACTION_SCREEN_ON" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
1.2) Then at end of the BroadcastReceiver send the intent to the right receiver:
#Override
public void onReceive(Context context, Intent intent) {
//Do your code for the other intents
new CampaignTrackingReceiver().onReceive(context, intent);
}
2) Calling the right Analytics version is also an issue when reading Google's tutorial because some links redirect you to older versions of the library all the time. If you are using v4 then:
2.1) Ensure not be including the libGoogleAnalyticsV2.jar
2.2) Double check that you are writing com.google.android.gms.analytics.CampaignTrackingService all the times and on all the imports.
3) When using the ADB to check if its working verify the previous points. On the above example, the right line to call the ADB will be:
adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n com.example/com.example.MyScheduleReceiver --es "referrer" "utm_source=testSource&utm_medium=testMedium&utm_term=testTerm&utm_content=testContent&utm_campaign=testCampaign"
For this make CustomReceiver and from that send intent to google CampaignTrackingReceiver in GoogleAnalyticsv4.
By this you will get CampaignFound in logs
public class CustomCampaignTrackingReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
new CampaignTrackingReceiver().onReceive(context, intent);
}
}
Install the apk file to you device.
adb install filename.apk
Type the following adb command:
..\sdk\platform-tools>adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n your.package.name/com.google.android.gms.analytics.CampaignTrackingReceiver --es "referrer" "utm_source=testSource"
Note that the command given in this link has a V3 Receiver.
Check logcat. The Campaign Found message should be there. Make sure the app is not running when the referrer is being sent. The app should be launched only after it is done.
Might be useful to someone... I was getting GAv4: Discarding hit. Missing tracking id parameter because instead of:
GoogleAnalytics.getInstance(context).newTracker(R.xml.app_tracker);
I've added
GoogleAnalytics.getInstance(context).newTracker(R.string.ga_trackingId);
Note the difference xml.app_tracker vs string.ga_trackingId!
Use xml.app_tracker configuration file!
As I checked in my last implementation. Maybe the log can be broken. I received "No campaign data found" in the logs, but I see real data in the web console.
I am using v4, and my manifest looks like this:
<receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<service android:name="com.google.android.gms.analytics.CampaignTrackingService" />
Good luck

how to know android app is installing/downloading

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>

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 broadcast receiver not getting called immediately after install

I have an Android app that listens to SMS messages. This is in the manifest:
<receiver android:name=".IncomingSMSBroadcastReceiver" android:enabled="true">
<intent-filter android:priority="100">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
The broadcast receivers works fine if the app is installed and opened. But I want the receiver to be able to be called immediately after install, in case user has remotely installed from the Android Market website and is not present in front of the phone. When I install APK using adb
./adb install myapp.apk
I can see the app is installed. But when I send a SMS message, my app doesnt respond. After I open the app once, it appears all the initialization happens at this point, and now the app responds to SMS messages just fine.
One possibility is that the ADB install is different from the Market install.
Any ideas?
It is not Possible. AFAIK until receiver is not registered then it can not detect any action.You have not any problem with code.But your receiver will work when it start one.For this we have to run our application at least one time.So that Manifest Register the Receiver

Categories

Resources