Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

 

Code Block
languagejava
titleCalling the service (This should happen ALWAYS after registering the receiver)
firstline1
linenumberstrue
Intent intent =  new Intent(“org.wso2.app.catalog.START_SERVICE”);
Intent explicitIntent = createExplicitFromImplicitIntent(context, intent);
if (explicitIntent != null) {
  intent = explicitIntent;
}
intent.putExtra("code", “APP_DOWNLOAD_PROGRESS”);

 

 

Code Block
languagejava
titleMethod to create an explicit intent
firstline1
linenumberstrue
public static Intent createExplicitFromImplicitIntent(Context context, Intent implicitIntent) {
  //Retrieve all services that can match the given intent
  PackageManager pm = context.getPackageManager();
  List<ResolveInfo> resolveInfo = pm.queryIntentServices(implicitIntent, 0);

  //Make sure only one match was found
  if (resolveInfo == null || resolveInfo.size() != 1) {
     return null;
  }

  //Get component info and create ComponentName
  ResolveInfo serviceInfo = resolveInfo.get(0);
  String packageName = serviceInfo.serviceInfo.packageName;
  String className = serviceInfo.serviceInfo.name;
  ComponentName component = new ComponentName(packageName, className);

  //Create a new intent. Use the old one for extras and such reuse
  Intent explicitIntent = new Intent(implicitIntent);

  //Set the component to be explicit
  explicitIntent.setComponent(component);

  return explicitIntent;
}


...