Skip to content

Instantly share code, notes, and snippets.

@luck-alex13
Created March 28, 2018 03:21
Show Gist options
  • Save luck-alex13/c3a936f3a7d4d5de81ede43aa0c01422 to your computer and use it in GitHub Desktop.
Save luck-alex13/c3a936f3a7d4d5de81ede43aa0c01422 to your computer and use it in GitHub Desktop.
Стартует сервис у которого в <intent-filter> прописан ACTION_CUSTOM_EVENT. Таким же образом можно стартануть активити
public static Intent convertImplicitIntentToExplicitIntent(Intent implicitIntent, Context context) {
PackageManager pm = context.getPackageManager();
List<ResolveInfo> resolveInfoList = pm.queryIntentServices(implicitIntent, 0);
if (resolveInfoList == null || resolveInfoList.size() != 1) {
return null;
}
ResolveInfo serviceInfo = resolveInfoList.get(0);
ComponentName component = new ComponentName(serviceInfo.serviceInfo.packageName, serviceInfo.serviceInfo.name);
Intent explicitIntent = new Intent(implicitIntent);
explicitIntent.setComponent(component);
return explicitIntent;
}
// somewhere in classes
Intent intent = new Intent();
intent.setAction(ACTION_CUSTOM_EVENT);
Context context = getApplicationContext();
Intent explicitIntent = convertImplicitIntentToExplicitIntent(intent, context);
if(explicitIntent != null){
context.startService(explicitIntent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment