Android Monodroid应用程序中的活动访问限制实现
我需要限制对Monodroid应用程序活动的访问。因此,我尝试了一个峰值,应用程序IntentSayHello将有一个名为SayHelloActivity的访问受限活动。作为第一步,我在应用程序的AndroidManifest.xml中定义了权限标记,如下所示:Android Monodroid应用程序中的活动访问限制实现,android,xamarin.android,Android,Xamarin.android,我需要限制对Monodroid应用程序活动的访问。因此,我尝试了一个峰值,应用程序IntentSayHello将有一个名为SayHelloActivity的访问受限活动。作为第一步,我在应用程序的AndroidManifest.xml中定义了权限标记,如下所示: ... ... </application> <permission android:name="intentsayhello.permission.SAYHELLO" android:prot
...
...
</application>
<permission
android:name="intentsayhello.permission.SAYHELLO"
android:protectionLevel="signature" android:label="@string/permlbl_restricted"
android:description="@string/permdesc_restricted">
</permission>
</manifest>
[Activity(Label = "SayHelloActivity", MainLauncher = true, Icon = "@drawable/icon", Permission = "intentsayhello.permission.SAYHELLO")]
[IntentFilter(new string[] { "companyXYZ.intent.sayhello.MAIN" },Categories = new string[]{Intent.CategoryDefault},
DataMimeType = "vnd.companyXYZ.say.hello/vnd.companyXYZ.activity")]
public class SayHelloActivity : Activity
{
.....
.....
}
...
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="intentsayhello.permission.SAYHELLO" />
</manifest>
<PropertyGroup>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
</PropertyGroup>
在此之后,我通过一个隐式意图调用intentsayHelloActivity of IntentSayHello,对一个客户端应用程序进行了测试,得到了预期的SecurityException
权限拒绝:启动意图{act=companyXYZ.Intent.sayhello.MAIN typ=vnd.companyXYZ.say.hello/vnd.companyXYZ.activity cmp=IntentSayHello.IntentSayHello/IntentSayHello.sayhello活动}
从ProcessRecord{4094f850 9126:DiffKeyHello.DiffKeyHello/10097}(pid=9126,uid=10097)需要intentsayhello.permission.SAYHELLO
现在,如果我想让我的客户端应用程序访问受限应用程序的SayHelloActivity,我应该使用相同的密钥库(证书)对客户端应用程序进行签名,并在客户端应用程序的AndroidManifest.xml中提到,如下所示:
...
...
</application>
<permission
android:name="intentsayhello.permission.SAYHELLO"
android:protectionLevel="signature" android:label="@string/permlbl_restricted"
android:description="@string/permdesc_restricted">
</permission>
</manifest>
[Activity(Label = "SayHelloActivity", MainLauncher = true, Icon = "@drawable/icon", Permission = "intentsayhello.permission.SAYHELLO")]
[IntentFilter(new string[] { "companyXYZ.intent.sayhello.MAIN" },Categories = new string[]{Intent.CategoryDefault},
DataMimeType = "vnd.companyXYZ.say.hello/vnd.companyXYZ.activity")]
public class SayHelloActivity : Activity
{
.....
.....
}
...
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="intentsayhello.permission.SAYHELLO" />
</manifest>
<PropertyGroup>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
</PropertyGroup>
。。。
但当我同时执行这两项操作时,客户端应用程序仍然无法调用SayHelloActivity,并引发了相同的SecurityException
我想知道这个问题的方向/解决方案。
谢谢在谷歌搜索之后,点击此页面: 我从这一页中得到了提示,即需要将数据放入客户端的AssemblyInfo.cs。语法是:
// Add some common permissions, these can be removed if not needed
[程序集:UsesPermission(“intentsayhello.permission.SAYHELLO”)]
[程序集:UsesPermission(Android.Manifest.Permission.Internet)]
在mono android论坛中进一步搜索,我发现另一种方法是在.csproj文件中显式添加androidmanifest.xml,如下所示:
...
...
</application>
<permission
android:name="intentsayhello.permission.SAYHELLO"
android:protectionLevel="signature" android:label="@string/permlbl_restricted"
android:description="@string/permdesc_restricted">
</permission>
</manifest>
[Activity(Label = "SayHelloActivity", MainLauncher = true, Icon = "@drawable/icon", Permission = "intentsayhello.permission.SAYHELLO")]
[IntentFilter(new string[] { "companyXYZ.intent.sayhello.MAIN" },Categories = new string[]{Intent.CategoryDefault},
DataMimeType = "vnd.companyXYZ.say.hello/vnd.companyXYZ.activity")]
public class SayHelloActivity : Activity
{
.....
.....
}
...
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="intentsayhello.permission.SAYHELLO" />
</manifest>
<PropertyGroup>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
</PropertyGroup>
属性\AndroidManifest.xml
以上两种方法都有效,只是我不知道哪一种/两者都是正确的做法