Created
March 28, 2018 03:21
-
-
Save luck-alex13/c3a936f3a7d4d5de81ede43aa0c01422 to your computer and use it in GitHub Desktop.
Стартует сервис у которого в <intent-filter> прописан ACTION_CUSTOM_EVENT. Таким же образом можно стартануть активити
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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