-
-
Save albodelu/5723c088e40bbce8093d1259c1a99e5d to your computer and use it in GitHub Desktop.
ACTION_MY_PACKAGE_REPLACED 사용하기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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