96

android – 从Preference Activity启动Activity导致Permission Denial Exception

 5 years ago
source link: https://codeday.me/bug/20190112/519034.html?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

我在这里遇到了一些问题.我想要做的是从PreferenceActivity中启动一个Activity.所以我的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>

猜猜看,当我想启动它时,我得到一个安全例外(Permission Denial).我错过了什么吗?我对意图的理解仍然有点不完整,但我认为它必须以这种方式工作.

感谢您的任何帮助!

制作一个意图过滤器似乎是一种略微迂回的方式.这是一种更简单的方法:
<PreferenceScreen
    android:title="@string/settings.title" 
    android:summary="@string/settings.summary">
    <intent
        android:targetPackage="com.companyname.appname"
        android:targetClass="com.companyname.appname.classname"/>
</PreferenceScreen>

翻译自:https://stackoverflow.com/questions/2077436/launch-activity-from-preference-activity-causes-permission-denial-exception


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK