我已经尝试了好几种方法,现在将所有操作都放入一个接收器中:
<receiver android:name=".ReceiverClass">
<intent-filter android:priority="1000">
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
<action android:name="android.intent.action.PACKAGE_INSTALL"/>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
这是我的接收器类
public class ReceiverClass extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction())) {
Toast.makeText(context, "1", Toast.LENGTH_LONG).show();
}
if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
Toast.makeText(context, "2", Toast.LENGTH_LONG).show();
System.out.println("test");
}
if (Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction())) {
Toast.makeText(context, "3", Toast.LENGTH_LONG).show();
System.out.println("test");
}
if (Intent.ACTION_PACKAGE_INSTALL.equals(intent.getAction())) {
Toast.makeText(context, "4", Toast.LENGTH_LONG).show();
System.out.println("test");
}
if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
Toast.makeText(context, "5", Toast.LENGTH_LONG).show();
System.out.println("test");
}
if (Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction())) {
Toast.makeText(context, "6", Toast.LENGTH_LONG).show();
System.out.println("test");
}
}
}
当我手动安装新的签名APK时,没有显示Toasts。我是否缺少某些内容,因为只有真正回复的帖子来自2015年甚至更早。时光飞逝。
根据ACTION_PACAKGE_INSTALL
,从未使用过[the documentation。