2011-07-16 15 views

答えて

8

ブロードキャストインテントIntent.ACTION_PACKAGE_ADDED(および/またはIntent.ACTION_PACKAGE_REMOVED,Intent.ACTION_PACKAGE_CHANGED)を登録できます。

void registerReceiver() { 
    IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); 
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED); 
    filter.addAction(Intent.ACTION_PACKAGE_CHANGED); 
    filter.addDataScheme("package"); 
    ... 
} 

public void onReceive(Context context, Intent intent) { 
    String actionStr = intent.getAction(); 
    if (Intent.ACTION_PACKAGE_ADDED.equals(actionStr)) { 
     Uri data = intent.getData(); 
     String pkgName = data.getEncodedSchemeSpecificPart(); 
     //handle package adding... 
    ... 
    } 
} 

コードは、次のようなものです

関連する問題