从偏好活动发射活动导致拒绝许可异常
-
21-09-2019 - |
题
我在这里有一点的问题。我想要做的就是从PreferenceActivity内推出一个活动。所以我preference.xml持有偏好的布局是这样的:
<Preference android:title="Launch Activity" >
<intent android:action="org.momo.SOME_ACTIVITY" />
</Preference>
在清单是知道我要开始练习的..
<activity android:label="@string/app_name" android:name="SomeActivity">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="org.momo.SOME_ACTIVITY" />
</intent-filter>
</activity>
你猜怎么着,我得到一个安全异常(许可拒绝)时,我想启动它。我缺少的东西吗?我的意图的理解仍然是一个有点不完整的,但我想它的必须的工作方式。
感谢您的帮助!
解决方案
制作意向滤波器好像这样做的稍微迂回的方式。这是一个简单的方法:
<PreferenceScreen
android:title="@string/settings.title"
android:summary="@string/settings.summary">
<intent
android:targetPackage="com.companyname.appname"
android:targetClass="com.companyname.appname.classname"/>
</PreferenceScreen>
其他提示
全工作示例 在preference.xml
<Preference
android:title="@string/settings_title_notification_silent_mode"
android:summary="@string/settings_title_notification_silent_mode_summary">
<intent
android:action="com.activity.SilentModeList"/> <!-- SilentModeList its activity -->
</Preference>
在您的manifest.xml
<activity android:name="com.activity.SilentModeList"
android:label="@string/ac_settings_description">
<intent-filter>
<action android:name="com.activity.SilentModeList" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
我在我的情况下我所有的XML设置是正确的。
但我发起活动(名为AppPreferences
)由于恶劣refractoring存在于的地方:[package].AppPreferences
和[[package].commmon.Preferences
因为一个import common._
,有人以此为活动,当然它并没有在Android清单中声明。
我只是从我的代码就万事大吉了删除第二项活动!
不隶属于 StackOverflow