没有收到ACTION_MY_PACKAGE_REPLACED [英] ACTION_MY_PACKAGE_REPLACED not received

查看:2074
本文介绍了没有收到ACTION_MY_PACKAGE_REPLACED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ACTION_MY_PACKAGE_REPLACED接收时,我的应用程序更新或resinstalled。 我的问题是,该事件被从未触发(我想Eclipse和实际装置)。 这是我做的:

I am using ACTION_MY_PACKAGE_REPLACED to receive when my app is updated or resinstalled. My problem is that the event is never triggered (I tried Eclipse and real device). This is what I do:

清单:

<receiver android:name=".MyEventReceiver" >
    <intent-filter android:priority="1000" >
        <action android:name="android.intent.action.ACTION_MY_PACKAGE_REPLACED" />
    </intent-filter>
</receiver>

code:

Code:

public class MyEventReceiver extends BroadcastReceiver
{  
   @Override public void onReceive(Context context, Intent intent)
   {  
      if ("android.intent.action.ACTION_MY_PACKAGE_REPLACED".equals(intent.getAction())) 
      {  //Restart services
      }
   }      
}

这code是简单,真正的我用其他的事件,如BOOT_COMPLETED和其他人,和他们的工作,但ACTION_MY_PACKAGE_REPLACED。 谢谢你。

This code is simple, in real one I used other events like BOOT_COMPLETED and others, and they work but ACTION_MY_PACKAGE_REPLACED. Thanks.

推荐答案

从所有用户获取信息,我可以解决我的情况就这样。 他们都是对的,少点需要注意:

Getting information from all the users I could solve my situation this way. All of them were right, with little points to notice:

在清单:

    <receiver android:name=".MyEventReceiver" >
        <intent-filter android:priority="1000" >
            <!--other actions I need-->
            <action android:name="android.intent.action.PACKAGE_REPLACED" />
            <data android:scheme="package"/>
        </intent-filter>
    </receiver>

和code:

public class MyEventReceiver extends BroadcastReceiver
{     
    @Override public void onReceive(Context context, Intent intent)
    {  
       if(Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction())) 
       {   if(intent.getData().getSchemeSpecificPart().equals(context.getPackageName()))
           {  //Restart services.
           }
       }
    }      
}

在我的Andr​​oid版本(2.3姜饼)我是不是能够使用MY_PACKAGE_REPLACED但我们解决了使用PACKAGE_REPLACED(会告知任何应用程序被替换),但询问是否是我们有:

In my Android release (2.3 Gingerbread) I was not able to use MY_PACKAGE_REPLACED but we solved using PACKAGE_REPLACED (will advise of any app been replaced) but asking if it is ours with:

 if(intent.getData().getSchemeSpecificPart().equals(context.getPackageName()))
 {
 }

感谢所有

这篇关于没有收到ACTION_MY_PACKAGE_REPLACED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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