function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MihahMihah 

Developing Hybrid App questions and problems

Hello All,

 

I am developing a Hybrid App with SalesforceMobileSDK for Android. I am using the latest SalesforceSDK library from github. I used the SFDCAccounts template and added smartstore functionalities. But I am facing some problems:

 

1. I have a problem with oAuth2 flow. I used the default functionalities from SDK, like they were set in the template. When I install the app and login, I have to allow oAuth and then I successfully login. If i close the app, and open it again everything is OK.. 

 

But If i dont use the app for like 1 hour, when I open it, I first see the home screen, but imediatelly after that the boostrap console lounches again and redirects me to login page where I again have to login and allow the oAuth.. How do I achieve the app to be connected all the time?


If i understand correctly, the SDK should keep the active session and take care of that itself? So is it a bug or do I have to change anything in my configuration?

 

2. I would like to use device functionalities. Is it possible to access the "phone" app, so for example, when a user clicks the button the phone would start to call a number? 

 

Thank you for your answers :)

 

Miha

 

AshwaniAshwani

Hi,

    Answer to your first question is that SalesforceMobileSDK in your first login stores the session id which is only from your login to logout period. Session id should expire after you close the app but takes few time. To acheive functionality of keed logged in you have to configure the mobile sdk to maintain ssesion id periodically by repeating the process of authentication and getting session id from the code (SalesforceAuthCoordinator is used for this) not from ui.

 

Secondly , we can access native features of mobile plateform. One of the framework to acheive this is "Phonegap". It provides various native features accessibilityin hybrid apps.

Gaurav KheterpalGaurav Kheterpal

A quick clarification on #2 - MobileSDK uses PhoneGap so all device features like email, phone are readily available in hybrid apps as well. If you are facing any specific problem with that, please post a thread with details and I'll be happy to help.

MihahMihah

Thank you for your answers.

 

For the first question, somehow, after disabling the "PIN protection" the app is working fine. Even if I dont use it for some time, when I reopen it, the authentication flow goes as it is supposed to go, and the home screen is shown..

 

For the second question, I also have managed to use the "tel:" keyword in a link:  <a href="tel:"></a>, which opens the "phone" app with the number inserted so the user only has to click "call"...

 

But I have one other question. Is it possible, to access a page on a customer portal from the app. The scenario is:

- On the customer portal, we have a visualforce page, which renders the PDF from the attachment, that user has.

- I would like to access that page, with the attachment ID from my app and then display the PDF in the app.

 

Is that possible? Could you also provide an example..

 

Thank you for your help.

Miha

Gaurav KheterpalGaurav Kheterpal

Good to know that you've #1 working now.

 

As for #2, that's the right approach.

 

For your other query - you can load any VF page from your hybrid app by loading it as follows

 

var startData = new SFHybridApp.RemoteAppStartData("/apex/BasicVFPage");

 

There's an example in the Mobile Workbook for it. There was a similar question on Stack Exchange which I answered a while back - http://salesforce.stackexchange.com/questions/7939/salesforce-base-url-in-android-rest-client

 

As for the attachment PDF rendering, I did not understand it clearly. Can you elaborate a bit more?

 

 

MihahMihah
Okay, so the main question is how to show the attachment file, that the portal user has attached to an object, inside the mobile hybrid app.

The attachment on the customer portal is rendered as PDF via the visualforce page and the renderAs="pdf" attribute. So when the user on the portal clicks a link, a generatePDF VF page is called which shows the PDF inside the browser.

I would like to show that same PDF in the mobile app. But, I have an app that uses REST to connect to SF, not the one with VF pages..

So, what I am trying to do, is to access the VF page inside the app. That page can only be accessed when the user is logged into the portal. So how can I show a PDF from the customer portal inside my mobile app?

I hope you understand now.

Regards,
Miha
Gaurav KheterpalGaurav Kheterpal

So your mobile app uses REST (not VF) and the PDF rendering logic is in the VF page (using the renderAs attribute) which requires the user to be able to logged in to the portal - correct?

 

If that's the case, I'm not sure if it would be feasible to show it via the VF page in your mobile app. Perhaps, Kevin Hawkins from the Salesforce Mobile SDK team or Patt Patterson can look at this thread and comment on it.

MihahMihah
Thank you for your answer.

Yes that is the case. However, i actually dont need to show it. It would
also be ok, to download it to the phone memory..

In the app, the user is already logged in as a portal user and has the
session and access token. Would it be possible, to use them in the URL and
access the VF page which would return the link of the PDF and then download
it to the phone?

If not, what would be the correct way to access and show an attachment in
the mobile app?

Regards,
Miha
AshwaniAshwani

PDF can be access through public site created in salesforce, which dont require to be login. And salesforce site can render visualforce page. Just create a  visualforce page which has "renderaAs="pdf" and expose it to site and pass required parameters accordingly. This way you can download pdf by sending request to that link. There may be other approach also but that worked for me.

 

MihahMihah
Thank you for the information.

I have one other problem regarding SmartStore. If I understand correctly, the created soups shoould get deleted, once the user logs out from the app with "SalesforceOAuthPlugin.logout()".

In my case, if I logout from the app and login again, the soup somehow doenst get deleted, since the "soupExists" method returns true. So I try to get the records from SmartStore, but there are no records in soup so I get the error: "Object__c does not have an index on Id".

What am I doing wrong? Before logout, I am sure there are records in the soup and the soup exists, so why doesnt the logout delete the soup and then fetch records from SF again?

Regards,
Miha