在android中安装后以编程方式启动应用程序
问题描述:
我已经开发了一个应用程序(测试),以便只要该应用程序具有最新版本的更新,它都将下载并安装最新的.apk文件.
I have developed an application(Test)such that whenever the application has updates with the latest version it will download and install the latest .apk file.
现在,我希望更新后自己启动/打开最新版本的应用程序.现在,我将在更新后手动启动该应用程序.我希望它自己做.
Now I want the latest version of application to launch/open by itself after updating. For now I am manually launching the application after update. I want it to do by itself.
请帮助.
谢谢
答
Android在安装应用时抛出广播.您可以在接收器中接收它,然后从那里启动它.
Android throws broadcast on installing app . You could receive it in receiver and launch from there.
<receiver
android:name="com.your.receiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package"/>
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED" />
在接收器中添加:
@Override
public void onReceive(Context context, Intent intent) {
//start activity
Intent i = new Intent();
i.setClassName("com.pkg", "com.pkg.yourStartActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}