我希望运行一项服务,只要我的应用在用户的设备中更新,我就会使用PACKAGE_REPLACED接收器来触发服务,同时还会显示一个toast来测试应用是否获得接收器事件或不。但吐司只在我启动应用程序后才显示,而不是在应用程序更新时。所以我的问题是:
清单文件
<?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>
按要求清单文件。
TIA