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, check checkselfpermission().
  • 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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -