2012-07-08 226 views

回答

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"); 
    } 


} 

}

相關問題