广播接收器MY_PACKAGE_REPLACED从未调用 [英] Broadcast Receiver MY_PACKAGE_REPLACED never called

查看:111
本文介绍了广播接收器MY_PACKAGE_REPLACED从未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下应用场景:1)自行更新的应用程序2)设备已植根3)在线检查版本,如果新版本在线,它将下载"apk"文件并安装

I have the following app scenario: 1) an app which updates by itself 2) the device is rooted 3) the checks for the version online and if new version is online it downloads the 'apk' file and installs it

一切正常,但安装新版本后APP无法重新启动.我试图设置MY_PACKAGE_REPLACED广播接收器,但从未调用过.该应用程序将安装新的程序并停止安装,但是该应用程序中的接收器永远不会触发.

Everything works fine but the APP does not restart after the new version install. I tried to set the MY_PACKAGE_REPLACED Broadcast Receiver, but it is never called. The app install new and stops but the receiver in the app is never triggered.

我在做什么错了?

代码:清单

<receiver android:name=".receivers.OnUpgradeReceiver">
            <intent-filter>
              <action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
              <data android:scheme="package"/>
          </intent-filter>
        </receiver>

我尝试了带有DATA部分且没有...的接收者清单代码,但仍然无法正常运行!

I tried the receiver manifest code with the DATA part and without ... and it still does not work!!

广播接收器类

public class OnUpgradeReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        final String msg="intent:"+intent+" action:"+intent.getAction();
        Log.e("OLE","RECEIVEEEEEEEEEEEEEEEEEEEEEED: "+msg);
    }}

APP更新部分

Process p;  
                    try {  

                        //Runtime.getRuntime().exec (new String[]{"su", "-c", "pm install -r " + apkLocation +  "party.net"});

                            // Preform su to get root privledges  
                            p = Runtime.getRuntime().exec("su");   

                            // Attempt to write a file to a root-only  
                            DataOutputStream os = new DataOutputStream(p.getOutputStream());  
                            os.writeBytes("/system/bin/pm install -r"+apkLocation+"\n");  

                            // Close the terminal  
                            os.writeBytes("exit\n");  
                            os.flush();  
                            try {  
                                    p.waitFor();
                                    if (p.exitValue() != 255) {  
                                            Log.e("OLE","Sucess :-)");
                                    }  
                                    else {  
                                        Log.e("OLE","Fail 1");
                                    }  

                            } catch (InterruptedException e) {  
                                Log.e("OLE","Fail 2");
                            }  
                    } catch (IOException e) {  
                        Log.e("OLE","Fail 3 "+e.getMessage());
                    }

已解决!问题在于安装在前一个版本之上的新版本没有设置广播接收器!!!

SOLVED! The problem was that the new VERSION which was installed above the previous one did not have the broadcast receiver set!!!

推荐答案

如果新应用未运行,则无法接收新应用的意图,最好的解决方案是使用另一个应用B来接收意图并运行新的应用程序A.

There is no way to receive intent for new app if the new one is not running, the best solution is to use another app-B to receive intent and run the new app-A.

这篇关于广播接收器MY_PACKAGE_REPLACED从未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆