List of usage examples for android.content IntentFilter addCategory
public final void addCategory(String category)
From source file:Main.java
public static boolean isMyLauncherDefault(Context context) { final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN); filter.addCategory(Intent.CATEGORY_HOME); List<IntentFilter> filters = new ArrayList<IntentFilter>(); filters.add(filter);// ww w . j a va 2s . c o m final String myPackageName = context.getPackageName(); List<ComponentName> activities = new ArrayList<>(); PackageManager packageManager = (PackageManager) context.getPackageManager(); // You can use name of your package here as third argument packageManager.getPreferredActivities(filters, activities, null); if (activities.size() == 0) //no default return true; for (ComponentName activity : activities) { if (myPackageName.equals(activity.getPackageName())) { return true; } } return false; }
From source file:it.jaschke.alexandria.receiver.NotificationBroadcastReceiver.java
/** * Creates a new instance of {@link NotificationBroadcastReceiver}, * assigns and registers it on the {@link LocalBroadcastManager}. * * @param context the {@link Context} used to get the * {@link LocalBroadcastManager}./* w w w. j a v a 2 s. co m*/ * @return the registered {@link NotificationBroadcastReceiver}. */ public static NotificationBroadcastReceiver registerLocalReceiver(Context context) { NotificationBroadcastReceiver broadcastReceiver = new NotificationBroadcastReceiver(); IntentFilter filter = new IntentFilter(BookService.ACTION_NOTIFY); filter.addCategory(BookService.CATEGORY_NO_RESULT); filter.addCategory(BookService.CATEGORY_DOWNLOAD_ERROR); filter.addCategory(BookService.CATEGORY_RESULT_PROCESSING_ERROR); filter.addCategory(BookService.CATEGORY_ALREADY_REGISTERED); filter.addCategory(BookService.CATEGORY_SUCCESSFULLY_ADDED); LocalBroadcastManager.getInstance(context).registerReceiver(broadcastReceiver, filter); return broadcastReceiver; }
From source file:com.google.android.gcm.GCMRegistrar.java
/** * Lazy initializes the {@link GCMBroadcastReceiver} instance. *//* www . j a v a 2 s .c o m*/ private static synchronized void setRetryBroadcastReceiver(Context context) { if (sRetryReceiver == null) { sRetryReceiver = new GCMBroadcastReceiver(); String category = context.getPackageName(); IntentFilter filter = new IntentFilter(GCMConstants.INTENT_FROM_GCM_LIBRARY_RETRY); filter.addCategory(category); // must use a permission that is defined on manifest for sure String permission = category + ".permission.C2D_MESSAGE"; Log.v(TAG, "Registering receiver"); context.registerReceiver(sRetryReceiver, filter, permission, null); } }
From source file:org.wso2.emm.agent.utils.CommonUtils.java
public static void registerSystemAppReceiver(Context context) { IntentFilter filter = new IntentFilter(Constants.SYSTEM_APP_BROADCAST_ACTION); filter.addCategory(Intent.CATEGORY_DEFAULT); SystemServiceResponseReceiver receiver = new SystemServiceResponseReceiver(); context.registerReceiver(receiver, filter); }
From source file:it.imwatch.nfclottery.MainActivity.java
/** * Sets up the dispatching of NFC events a the foreground Activity. * * @param activity The {@link android.app.Activity} to setup the foreground dispatch for * @param adapter The {@link android.nfc.NfcAdapter} to setup the foreground dispatch for *///from w w w . jav a2 s .co m public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) { if (adapter != null) { final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass()); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0); IntentFilter[] filters = new IntentFilter[1]; String[][] techList = new String[][] {}; // Notice that this is the same filter we define in our manifest. // This ensures we're not stealing events for other types of NDEF. filters[0] = new IntentFilter(); IntentFilter filter = filters[0]; filter.addAction(NfcAdapter.ACTION_NDEF_DISCOVERED); filter.addCategory(Intent.CATEGORY_DEFAULT); try { filter.addDataType(MIME_VCARD); filter.addDataType(MIME_XVCARD); } catch (IntentFilter.MalformedMimeTypeException e) { throw new RuntimeException("Mime type not supported."); } adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList); } }
From source file:Main.java
private static final boolean initIntentFilterFromXml(IntentFilter inf, XmlPullParser xpp) { try {//from w w w. j a v a 2 s .c o m int outerDepth = xpp.getDepth(); int type; final String NAME = "name"; while ((type = xpp.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || xpp.getDepth() > outerDepth)) { if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) continue; String tag = xpp.getName(); if (tag.equals("action")) { String name = xpp.getAttributeValue(null, NAME); if (name != null) inf.addAction(name); } else if (tag.equals("category")) { String name = xpp.getAttributeValue(null, NAME); if (name != null) inf.addCategory(name); } else if (tag.equals("data")) { int na = xpp.getAttributeCount(); for (int i = 0; i < na; i++) { String port = null; String an = xpp.getAttributeName(i); String av = xpp.getAttributeValue(i); if ("mimeType".equals(an)) { try { inf.addDataType(av); } catch (MalformedMimeTypeException e) { } } else if ("scheme".equals(an)) { inf.addDataScheme(av); } else if ("host".equals(an)) { inf.addDataAuthority(av, port); } else if ("port".equals(an)) { port = av; } else if ("path".equals(an)) { inf.addDataPath(av, PatternMatcher.PATTERN_LITERAL); } else if ("pathPrefix".equals(an)) { inf.addDataPath(av, PatternMatcher.PATTERN_PREFIX); } else if ("pathPattern".equals(an)) { inf.addDataPath(av, PatternMatcher.PATTERN_SIMPLE_GLOB); } } } } return true; } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:io.rapidpro.androidchannel.UnclaimedFragment.java
public void onAttach(android.app.Activity activity) { super.onAttach(activity); m_receiver = new ClaimCodeReceiver(); IntentFilter filter = new IntentFilter(); filter.addAction(Intents.UPDATE_RELAYER_STATE); filter.addCategory(Intent.CATEGORY_DEFAULT); activity.registerReceiver(m_receiver, filter); }
From source file:com.facebook.react.tests.ShareTestCase.java
public void testShowBasicShareDialog() { final WritableMap content = new WritableNativeMap(); content.putString("message", "Hello, ReactNative!"); final WritableMap options = new WritableNativeMap(); IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CHOOSER); intentFilter.addCategory(Intent.CATEGORY_DEFAULT); ActivityMonitor monitor = getInstrumentation().addMonitor(intentFilter, null, true); getTestModule().showShareDialog(content, options); waitForBridgeAndUIIdle();//from w w w . j a va2 s.c om getInstrumentation().waitForIdleSync(); assertEquals(1, monitor.getHits()); assertEquals(1, mRecordingModule.getOpened()); assertEquals(0, mRecordingModule.getErrors()); }
From source file:monakhv.android.samlib.BooksActivity.java
@Override protected void onResume() { super.onResume(); if (author_id != -1) { AuthorController sql = new AuthorController(this); Author a = sql.getById(author_id); setTitle(a.getName());//from www .j a va 2 s .co m } else { setTitle(getText(R.string.menu_selected_go)); } receiver = new DownloadReceiver(); IntentFilter filter = new IntentFilter(DownloadReceiver.ACTION_RESP); filter.addCategory(Intent.CATEGORY_DEFAULT); registerReceiver(receiver, filter); }
From source file:org.wso2.app.catalog.services.AppCatalogService.java
/** * Executes device management operations on the device. * * @param code - Operation object.// ww w . j av a 2 s . c o m */ public void doTask(String code) { switch (code) { case Constants.Operation.GET_APP_DOWNLOAD_PROGRESS: String downloadingApp = Preference.getString(context, context.getResources().getString(R.string.current_downloading_app)); JSONObject result = new JSONObject(); ApplicationManager applicationManager = new ApplicationManager(context); if (applicationManager.isPackageInstalled(Constants.AGENT_PACKAGE_NAME)) { IntentFilter filter = new IntentFilter(Constants.AGENT_APP_ACTION_RESPONSE); filter.addCategory(Intent.CATEGORY_DEFAULT); AgentServiceResponseReceiver receiver = new AgentServiceResponseReceiver(); registerReceiver(receiver, filter); CommonUtils.callAgentApp(context, Constants.Operation.GET_APP_DOWNLOAD_PROGRESS, null, null); } else { try { result.put(INTENT_KEY_APP, downloadingApp); result.put(INTENT_KEY_PROGRESS, Preference.getString(context, context.getResources().getString(R.string.app_download_progress))); } catch (JSONException e) { Log.e(TAG, "Result object creation failed" + e); sendBroadcast(Constants.Status.INTERNAL_SERVER_ERROR, null); } sendBroadcast(Constants.Status.SUCCESSFUL, result.toString()); } break; default: Log.e(TAG, "Invalid operation code received"); break; } }