I can't seem to catch this and I also can't see it being sent in Logcat. From reviewing ACTION_MY_PACKAGE_REPLACED not received, it appears MY_PACKAGE_REPLACED should be all I need for API22.
What am I missing?
Thank you.
Snippet from AndroidManifest.xml
<receiver
android:name=".BootReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver>
BootReceiver
class BootReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == "android.intent.action.BOOT_COMPLETED" ||
intent.action == "android.intent.action.MY_PACKAGE_REPLACED") {
Log.d(TAG, "Caught BOOT_COMPLETED or PACKAGE_REPLACED action!")
GlobalScope.launch(Dispatchers.IO) {
...
}
}
}
}
Upon further investigation, this works properly if Android Studio (AS) is removed from the picture; use it to build the APK and, perhaps, view Logcat, but that’s it. If I only install/replace the app from the command line/Terminal, and do not Run app and related from AS, this works as intended. In my case, since I frequently install/Run from AS, I had to do the following TWICE and android.intent.action.MY_PACKAGE_REPLACED was caught the SECOND time:
adb -s emulator-5554 install -r app-debug.apk
I repeat, running the app from Android Studio, in this regard, severally messes with android.intent.action.MY_PACKAGE_REPLACED and I, sadly, lost a couple of hours figuring this out!
Related
Broadcast which should be sent to the application just after app is installed on TV is not received.
I declared BR in Manifest.xml:
<receiver
android:name=".RunOnInstallReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.media.tv.action.INITIALIZE_PROGRAMS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
I declared also:
<uses-feature
android:name="android.software.leanback"
android:required="true" />
RunOnInstallReceiver class is very simple:
public class RunOnInstallReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.v("RAMPS", "Broadcast received");
}
}
I tried with nVidia Shield and Mi Box 3 - no success. Anyone had similar problem?
Are you side loading the application? INITIALIZE_PROGRAMS is only sent when the application is installed via the store.
When side loading (installing from adb or android studio), you can trigger the intent with:
adb shell am broadcast -a android.media.tv.action.INITIALIZE_PROGRAMS -n com.your.app.package/.YourReceiver
Answer is from bullet #5 in Android developer guide for creating a channel on the home screen: https://developer.android.com/training/tv/discovery/recommendations-channel#creating_a_channel
In my case, if you use product flavor you should trigger by:
adb shell am broadcast -a android.media.tv.action.INITIALIZE_PROGRAMS -n X/Y
X is your applicationID.
Y is the link of your broadcast received file in your project.
Example: You build your application with Build variants staging and trigger is:
adb shell am broadcast -a android.media.tv.action.INITIALIZE_PROGRAMS -n com.google.android.staging/com.google.android.tvhomescreenchannels.RunOnInstallReceiver
Here is ApplicationId:
Here is path RunOnInstallReceiver:
Please find the below code for more information.
<receiver
android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
android:exported="true"
android:enabled="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER"/>
</intent-filter>
</receiver>
<service android:name="com.google.android.gms.analytics.CampaignTrackingService"
android:enabled="true"/>
This is what I have done for implementing Campaign Measurement - Android SDK v4.
In order to check is it working or not, when I try to run this on terminal:
adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n
"com.example.android/com.google.android.gms.analytics.CampaignTrackingReceiver"
--es referrer "utm_source=testSource&utm_medium=testMedium&utm_term=testTerm&utm_content=testContent&utm_campaign=testCampaign"
it successfully cast an intent
Broadcasting: Intent { act=com.android.vending.INSTALL_REFERRER
cmp=com.example.android/com.google.android.gms.analytics.CampaignTrackingReceiver
(has extras) } Broadcast completed: result=0
and when I run my application I get the log as follows:
CampaignTrackingReceiver is not registered, not exported or is disabled. Installation campaign tracking is not possible. See http://goo.gl/8Rd3yj for instructions.
I had tried many example but not got the sufficient result. Anyone if knows the whole working then please provide me a link or if anybody knows the exact steps plz list them.
Thanxx in advance
I'm not getting install referrer received on application installed from the play store. Below is my Androidmanifest.xml shows receiver which is inside <application> tag too.
<receiver
android:name="com.usplnew.getreferrer.CustomReceiver"
android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
And below is code for Receiver
public class CustomReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
System.out.println("sgn RECEIVED");
Log.d("YES", "IT WORKS!!");
Toast.makeText(context, "Received Intall Referrer", Toast.LENGTH_SHORT)
.show();
}
}
Its working well with below command on emulator and device too
adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n com.uspl.getrefferer/com.uspl.getrefferer.CustomReceiver --es "referrer" "https://play.google.com/store/apps/details?id=com.NextGen.Water.Run&referrer=IWantThisReferrer"
I also put the same below code into the app into the production on Google Play. But INSTALL REFERRER is not received when the application is installed.
I would highly appreciate if someone guide where I'm wrong.
Thanks in Advance!
Have you checked your implementation of your own class of BroadcastReceiver with this documentation - https://developers.google.com/analytics/devguides/collection/android/v1/devguide#campaigns
?
I have implemented Broadcast Receiver in a library project for checking the Boot Completed event , but it is not working.
Broadcast Receiver Class :
public class Reciever extends BroadcastReceiver
{
public void onReceive(Context context, Intent intent)
{
if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))
{
Toast.makeText(context, "Device Boot Completed", Toast.LENGTH_LONG).show();
}
}
}
AndroidManifest.xml :
<receiver
android:name=".Reciever"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
I implemented same Receiver in another application (not library project) and it is working fine.
BroadcastReceiver cannot be defined in the library project's manifest. The hosting project always needs to declare the components.
android library project and Activities
Edit:
I feel this should work with latest Android studio/ gradle based projects.
You might skipped
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
In manifest file
Override the following method
#Override
public void onReceive(Context context, Intent intent)
You should add receive tag and reboot permissions to client application manifest file which using your library jar
Like this;
<receiver android:name="com.example.library.ReceiverClass"
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
I am trying to start the service from adb shell. There already is similar question: How to start and stop android service from a adb shell?
However, when I start service with:
adb shell am startservice com.mypackage/com.mypackage.service.MyService
I receive this message:
Starting service: Intent { act=android.intent.action.VIEW dat=com.mypackage/com.mypackage.service.MyService }
Error: Not found; no service started.
I declare service in AndroidManifest.xml:
<application>
...
<service
android:name="com.mypackage.service.MyService"
android:label="#string/local_service_label"
android:icon="#drawable/ic_launcher">
</service>
</application>
Do you have any idea how to solve this?
Thank you!
adb shell am startservice -n com.mypackage/.service.MyService
Update (Per adb shell am help start-service):
-n <COMPONENT_NAME>
Consider the below as an example
<application android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme">
<service
android:name=".MyService"
android:description="#string/Desciption"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.nandhan.myservice" />
</intent-filter>
</service>
</application>
Then I would start the service as below
adb shell am startservice com.nandhan.myservice/.MyService
In my case, the service failing to start was com.android.tools.fd.runtime.InstantRunService.
Starting service: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.xxx.xxx/com.android.tools.fd.runtime.InstantRunService }
Error: Not found; no service started.
Turns out my android device was missing something. To disable it, go to preferences > Build, Execution, Deployment > Instant Run and uncheck Enable Instant Run to hot swap code/resource changes on deploy (default enabled).
According to that screenshot, it's better to keep it and indeed, I'd be happier with that feature. At least I ran with extra logging and sent feedback to google. I just needed a build asap so no instant run for me today ;)
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.xyz.path">
...
<application
...
<service android:name=".MyService">
<intent-filter>
<action android:name="com.xyz.path.MY_SERVICE" />
</intent-filter>
</service>
...
Command:
adb shell am startservice -n com.xyz.path/.MyService