Skip to content

Instantly share code, notes, and snippets.

@albodelu
Forked from jungilhan/AndroidManifest.xml
Created December 10, 2019 19:19
Show Gist options
  • Save albodelu/5723c088e40bbce8093d1259c1a99e5d to your computer and use it in GitHub Desktop.
Save albodelu/5723c088e40bbce8093d1259c1a99e5d to your computer and use it in GitHub Desktop.
ACTION_MY_PACKAGE_REPLACED 사용하기
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mypackagereplaced"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.mypackagereplaced.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".Receiver" >
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver>
</application>
</manifest>
package com.example.mypackagereplaced;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.widget.Toast;
public class Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_MY_PACKAGE_REPLACED)) {
try {
PackageManager pm = context.getPackageManager();
PackageInfo info = pm.getPackageInfo(context.getPackageName(), 0);
String versionName = info.versionName;
int versionCode = info.versionCode;
Toast.makeText(context, "[My Package replaced] name: " + versionName + " code: " + versionCode, Toast.LENGTH_LONG).show();
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment