+ Start a Discussion
mnnit.laltukumar1.391409072680632E12mnnit.laltukumar1.391409072680632E12 

Implementation of oauth for android using salesforce.

Hi All,
I have created this app for creating custom login for salesforce in android.But while running I am getting binding error "No account of type com.salesforce.androisdk found" . I don't have any idea what this is about can anyone has any idea can share.. 





public class MainActivity extends SalesforceActivity  {

private RestClient client;
private ArrayAdapter<String> listAdapter;
private static String TAG = "TemplateApp";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.v(TAG," onCreate of Main Activity");
    // Setup view
    setContentView(R.layout.main);
}

@Override
public void onResume() {
    Log.v(TAG," ******* default onResume of Main Activity");
        super.onResume();

        findViewById(R.id.root).setVisibility(View.VISIBLE);
        Log.v(TAG," ******* default onResume - View.INVISIBLE");

        // Login options
        String accountType = SalesforceSDKManager.getInstance().getAccountType();

        Log.v(TAG," ******* default onResume - accountType ::"+accountType);

        LoginOptions loginOptions = new LoginOptions(
                "https://login.salesforce.com/", // login host is chosen by user through the server picker
                SalesforceSDKManager.getInstance().getPasscodeHash(),
                getString(R.string.oauth_callback_url),
                getString(R.string.oauth_client_id),
                new String[] {"api"});
        Log.v(TAG," ******* default onResume - loginOptions ::"+loginOptions);


        // Get a rest client
        new ClientManager(this, accountType, SalesforceSDKManager.getInstance().getLoginOptions(),SalesforceSDKManager.getInstance().shouldLogoutWhenTokenRevoked()).getRestClient(this,
                       new RestClientCallback() {
            @Override
            public void authenticatedRestClient(RestClient client) {

                // Show everything
                findViewById(R.id.root).setVisibility(View.VISIBLE);

              
     if (client == null) {
      SalesforceSDKManager.getInstance().logout(MainActivity.this);
      return;
     }
     onResume(client);

     // Lets observers know that rendition is complete.
     EventsObservable.get().notifyEvent(EventType.RenditionComplete);
    }
   });
            }
   


protected LoginOptions getLoginOptions() {
    Log.v(TAG," getLoginOptions of Main Activity");
    LoginOptions loginOptions = new LoginOptions(
            null, // login host is chosen by user through the server picker
            SalesforceSDKManager.getInstance().getPasscodeHash(),
            getString(R.string.oauth_callback_url),
            getString(R.string.oauth_client_id),
            new String[] {"api"});
    return loginOptions;
}

public void onResume(RestClient client) {
    Log.v(TAG," onResume of Main Activity");
    // Keeping reference to rest client
    this.client = client;

    // Show everything
    findViewById(R.id.root).setVisibility(View.VISIBLE);
}

/**
* Called when "Logout" button is clicked.
*
* @param v
*/
public void onLogoutClick(View v) {
SalesforceSDKManager.getInstance().logout(this);
}

/**
* Called when "Clear" button is clicked.
*
* @param v
*/

public void onClearClick(View v) {
    listAdapter.clear();
}  

/**
* Called when "Fetch Contacts" button is clicked
*
* @param v
* @throws UnsupportedEncodingException
*/

public void onFetchContactsClick(View v) throws UnsupportedEncodingException {
    sendRequest("SELECT Name FROM Contact");
}

public void onFetchAccountsClick(View v) throws UnsupportedEncodingException {
    sendRequest("SELECT Name FROM Account");
}  

private void sendRequest(String soql) throws UnsupportedEncodingException {
    RestRequest restRequest = RestRequest.getRequestForQuery(getString(R.string.api_version), soql);

    client.sendAsync(restRequest, new AsyncRequestCallback() {
        @Override
        public void onSuccess(RestRequest request, RestResponse result) {
            try {
                listAdapter.clear();
                JSONArray records = result.asJSONObject().getJSONArray("records");
                for (int i = 0; i < records.length(); i++) {
                    listAdapter.add(records.getJSONObject(i).getString("Name"));
                }                  
            } catch (Exception e) {
                onError(e);
            }
        }

        @Override
        public void onError(Exception exception) {
            Toast.makeText(MainActivity.this,
                           MainActivity.this.getString(SalesforceSDKManager.getInstance().getSalesforceR().stringGenericError(), exception.toString()),
                           Toast.LENGTH_LONG).show();
        }
    });
}
bhariharanbhariharan
The error message you are getting means that the user hasn't logged in yet, and hence, there's no valid Salesforce account yet. This message is received when you try to obtain a RestClient before the user has logged in. Typically, if setup correctly, when this error message occurs, the LoginActivity should popup and once the user logs in, you will receive a valid RestClient instance. Are you using a custom LoginActivity or the default one? What version of the Mobile SDK are you using? Can you post the SalesforceSDKManager.init() call you've made here?
mnnit.laltukumar1.391409072680632E12mnnit.laltukumar1.391409072680632E12
I am using the default the Login Activity provided in the SDK.
While running the app the error keeps coming like a loop and activity just keep restarting itself.
I am using version 2.1.0

Here's my SDKManager.init() call

public class TemplateApp extends Application{

@Override
public void onCreate() {
  super.onCreate();
 SalesforceSDKManager.initNative(getApplicationContext(), new KeyImpl(), MainActivity.class);