android - Filter activities with permission requirements -
i'm trying let user choose application app should send specific intent to. list of candidates, queryintentactivities()
works, except applications define accepting activity permission
requirement, can't start them. so, can filter them out in of these ways?
- have
packagemanager
filter them out me. - from
resolveinfo
, check if activity (or parent application) requires permission, checkcheckselfpermission()
. - start activity picker (which filters them since android 4.1) , somehow activity picked.
api level 22 has version of createchooser() lets use system activity chooser , receive chosen activity in broadcast.
in older versions following method works:
list<resolveinfo> candidates = pm.queryintentactivities(intent, 0); (int = candidates.size() - 1; >= 0; --i) { resolveinfo resolveinfo = candidates.get(i); string permission = resolveinfo.activityinfo.permission; if (permission == null) permission = resolveinfo.activityinfo.applicationinfo.permission; if (permission != null && contextcompat.checkselfpermission(this, permission) != packagemanager.permission_granted) candidates.remove(i); }
Comments
Post a Comment