2015-10-09 45 views

回答

1

在設置:

MockPackageManager mockPackageManager = new MockPackageManager(
    Robolectric.getShadowsAdapter()); 
RuntimeEnvironment.setRobolectricPackageManager(mockPackageManager); 

子類:

class MockPackageManager extends DefaultPackageManager { 

    public MockPackageManager(ShadowsAdapter shadowsAdapter) { 
    super(shadowsAdapter); 
    } 

    @Override 
    public String getNameForUid(int uid) { 
    switch (uid) { 
     case UID_A: 
     return NAME_A; 
     case UID_B: 
     return NAME_B; 
     default: 
     return null; 
    } 
    } 

    @Override 
    public boolean isPermissionRevokedByPolicy(String s, String s1) { 
    return false; 
    } 
} 
+0

酷!你還可以在Robolectric github上創建一個問題嗎? –