BroadcastReceiver for Package_Install无法正常工作

时间:2013-02-28 09:35:02

标签: android android-intent broadcastreceiver

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

    // TODO Auto-generated method stub
    Toast.makeText(context, "Package Received", Toast.LENGTH_SHORT).show();
    Log.d("Package Installing", "Package Installing");
    String action=intent.getAction();
    if(action.equals(intent.ACTION_PACKAGE_INSTALL))
    {
        Toast.makeText(context, "Package Added", Toast.LENGTH_SHORT).show();
        Log.d("Package INstalling", "Package Installed");
    }
}

//我的清单文件:

<receiver android:name="com.example.anotherbroadcastreceiverexample.MyReceiver" android:enabled="true">
            <intent-filter><action android:name="android.intent.action.PACKAGE_INSTALL"/></intent-filter>

    </receiver>

1 个答案:

答案 0 :(得分:0)

您是否可以尝试以下列方式修改您的清单:

<intent-filter>
    <action android:name="android.intent.action.PACKAGE_INSTALL" />
    <action android:name="android.intent.action.PACKAGE_ADDED" />
    <data android:scheme="package"/>
</intent-filter>

<强>更新

检查不是PACKAGE_INSTALL检查操作PACKAGE_ADDED。