Android:安装后检测应用程序

时间:2012-07-08 12:18:31

标签: android installation detect

我正在从服务器下载Android应用并安装它。我想检测安装何时完成。我试过这个link,但它不起作用。还有其他例子吗?

1 个答案:

答案 0 :(得分:2)

把它放在你的清单中:

<manifest>
    ....
    <application>
        ....
        <receiver android:name=".YourReceiver">
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_ADDED">
            </intent-filter>
        </receiver>
    </application>
</manifest>

然后,创建一个YourReceiver类并输入以下内容:

public class YourReceiver extends BroadcastReceiver{

final static String TAG = "YourReceiver";

@Override
public void onReceive(Context context, Intent intent) {

    Log.i(TAG, "Intent received!");

    Uri data = intent.getData();
    String pkgName = data.getEncodedSchemeSpecificPart();

    if (pkgName.equals("some.app.name")) {

        Log.i(TAG, "Package installed");
    }


}

}