نشاط الإطلاق من نشاط التفضيل يسبب استثناء رفض الإذن

StackOverflow https://stackoverflow.com/questions/2077436

سؤال

أواجه مشكلة صغيرة هنا. ما أريد القيام به هو إطلاق نشاط من داخل النشاط. لذا فإن تفضيلاتي.

<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>

نصائح أخرى

مثال العمل بالكامل في تفضيلاتك. 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>

في manisest.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) بسبب الانكسار السيئ موجود في الأماكن: [package].AppPreferences و[ [package].commmon.Preferencesبسبب import common._, ، كان يأخذ هذا كنشاط وبالطبع لم يتم الإعلان عنه في بيان Android. اضطررت فقط إلى حذف النشاط الثاني من الكود وفويلا!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top