2012-06-12 11 views
5

मैंने एक प्रमाणीकरणकर्ता बनाया है, मैंने एक सिंक एडाप्टर बनाया है (दोनों को एमुलेटर पर सेटिंग्स के माध्यम से मैन्युअल रूप से निष्पादित किया जा सकता है)।एंड्रॉइड प्रमाणक लॉन्च स्क्रीन जब कोई खाता मौजूद नहीं है

कोई खाता नहीं मिलने पर ऐप लॉन्च होने पर लॉगिन स्क्रीन (ऐडकाउंट विधि) लॉन्च करने के लिए मैं अपना आवेदन कैसे प्राप्त करूं?

यहाँ मेरी Manifest.xml है ...

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.lateral.myapp" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="14"/> 

    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.GET_ACCOUNTS"/> 
    <uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/> 
    <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/> 
    <uses-permission android:name="android.permission.USE_CREDENTIALS"/>  
    <uses-permission android:name="android.permission.READ_SYNC_STATS" /> 
    <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" /> 
    <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" /> 

    <application android:icon="@drawable/icon" android:label="@string/app_name" android:name=".myappApplication"> 
     <activity android:name=".ui.EventListActivity"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN"/> 

       <category android:name="android.intent.category.LAUNCHER"/> 
      </intent-filter> 
     </activity> 

     <service android:name=".authenticator.AccountAuthenticatorService" android:exported="true" android:process=":auth"> 
      <intent-filter> 
       <action android:name="android.accounts.AccountAuthenticator"/> 
      </intent-filter> 
      <meta-data android:name="android.accounts.AccountAuthenticator" android:resource="@xml/authenticator"/> 
     </service> 

     <service android:name="sync.EventsSyncAdapterService" android:exported="true" android:process=":events"> 
      <intent-filter> 
       <action android:name="android.content.SyncAdapter" /> 
      </intent-filter> 
      <meta-data android:name="android.content.SyncAdapter" android:resource="@xml/sync_events" /> 
     </service> 

     <activity android:excludeFromRecents="true" android:name=".authenticator.myappAuthenticatorActivity"> 
      <!-- 
       No intent-filter here! This activity is only ever launched by 
       someone who explicitly knows the class name 
      --> 
     </activity> 
    </application> 

</manifest> 

उत्तर

4

AccountManager काम के माध्यम से नहीं जा रहा है? कुछ ऐसा:

AccountManager accountManager = AccountManager.get(this); 
Account[] accounts = accountManager.getAccountsByType("myCustomAccount"); 
if (accounts.length == 0) { 
    accountManager.addAccount("myCustomAccount", null, null, null, this, 
           null, null); 
    } 
+0

जहां जाना होगा? – Rabbott

+0

अपने ऐप में :) उपयोगकर्ता को खाता हटाते समय केस को संभालने के लिए 'ऑनर्यूम()' से कॉल करें और फिर अपने ऐप पर वापस जाएं। –

+0

परफेक्ट - जैसा कि @ zed-scio द्वारा उल्लिखित है, मैं लॉग इन स्क्रीन से पहले प्रदर्शित होने से दूसरे इरादे को कैसे रोकूं .. इस बिंदु पर ऑनस्यूम विधि में केवल आपका कोड और 'super.onResume();' लेकिन – Rabbott

1

अपनी 'EventListActivity' ऑनक्रेट में, यह देखने के लिए जांचें कि क्या कोई खाता है या नहीं। यदि नहीं हैं, तो प्रमाणीकरण गतिविधि खोलें। यदि आप EventListActivity के UI शो से पहले, यह जांच करना और प्रमाणीकरणकर्ता बनाना चाहते हैं, तो आपको केवल ऑनक्रेट विधि में 'setContentView' से पहले कोड जोड़ना होगा।

+0

तो ऐसा कुछ नहीं होता है, मैंने इसे मैन्युअल रूप से किया है और इरादा लॉन्च करें? मैंने सोचा कि एंड्रॉइड इसे उठाएगा और लॉन्च नहीं करेगा अगर कुछ भी पता नहीं चला है .. – Rabbott

+0

मुझे लगा कि आप कह रहे थे कि आपने अपना खाता प्रबंधक वर्ग बनाया है। अगर ऐसा नहीं है। नीचे प्रयोग करें –

0

लॉगिन स्क्रीन पर नहीं जाने पर खाता मौजूद है या नहीं।

public static boolean accountExists(Context ctx, AccountManager accountManager) { 
Account[] accounts = accountManager.getAccountsByType(
    ctx.getString(R.string.account_type) 
); 
return accounts.length > 0; 
} 
संबंधित मुद्दे