import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class refreshapp_br extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent arg1) {
// TODO Auto-generated method stub
String action = arg1.getAction();
if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
//Log.d(TAG, "package has been removed");
String packageName = arg1.getData().getSchemeSpecificPart();
//Log.d(TAG, packageName);
Toast.makeText(context, " "+packageName, Toast.LENGTH_SHORT).show();
} else if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
//Log.d(TAG, "package has been added");
String packageName = arg1.getData().getSchemeSpecificPart();
Toast.makeText(context, " "+packageName, Toast.LENGTH_SHORT).show();
}
}
}
----------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testgetinstalledapp"
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.testgetinstalledapp.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="com.example.testgetinstalledapp.refreshapp_br" >
<intent-filter android:priority="999" >
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
</application>
</manifest>
沒有留言:
張貼留言