0

I want to run a service, whenever My app gets updated in user's device for that I'm using PACKAGE_REPLACED receiver to trigger the service, also showing a toast to test if the app getting the receiver event or not. But toast only shows after I start the application not when the application is updated. So my Questions are:

  1. Is it possible to fire an event when app gets updated not started? because of toast requires app context that's why it's triggering showToast() when the app gets started?
  2. Is it required to handle PACKAGE_REPLACED receiver in previous versions also, then only it will work? Just want to know the flow the PACKAGE_REPLACED.

Manifest File

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.myapp.app">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />

    <!-- Keeps the processor from sleeping when a message is received. -->
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />


    <!-- location permission to detect the user permission-->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <!-- Needed only if your app targets Android 5.0 (API level 21) or higher. -->
    <uses-feature android:name="android.hardware.location.gps" />

    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

    <!-- Network State Permissions to detect Internet status -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <!-- Permission to vibrate -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <uses-permission android:name="android.permission.VIBRATE" />

    <uses-permission android:name="com.sec.android.provider.badge.permission.READ" />
    <uses-permission android:name="com.sec.android.provider.badge.permission.WRITE" />

    <application
        android:name=".myappApp"
        android:allowBackup="true"
        android:hardwareAccelerated="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:theme="@style/AppTheme">

        <meta-data
            android:name="GCM_SENDER_ID"
            android:value="id:ptune-openlogin" />
        <meta-data
            android:name="CLEVERTAP_NOTIFICATION_ICON"
            android:value="notification_icon" />

        <service
            android:name=".gcm.StickyService"
            android:enabled="true"></service>

        <receiver
            android:name=".gcm.ServiceReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_REPLACED" />
                <data android:scheme="package" />
            </intent-filter>
        </receiver>
        //

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="open"
                    android:scheme="myapp" />
            </intent-filter>
            <!-- AppLink example -->
            <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:host="bitly.app.link"
                    android:scheme="https" />
                <data
                    android:host="bitly.test-app.link"
                    android:scheme="https" />
                <data
                    android:host="app.link"
                    android:pathPrefix="/0A3dz2UUyD"
                    android:scheme="https" />
                <data
                    android:host="test-app.link"
                    android:pathPrefix="/qa-link"
                    android:scheme="https" />
            </intent-filter>
        </activity>

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
       ...
    </application>

</manifest>

Manifest file as requested.

TIA

Parvinder Singh
  • 163
  • 3
  • 11

0 Answers0