我正在从服务器下载Android应用并安装它。我想检测安装何时完成。我试过这个link,但它不起作用。还有其他例子吗?
答案 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");
}
}
}