How to get the ID of the apps script inside a spreadsheet - android

My program works like this:
1 - Make a copy of a public google spreadsheet to my drive account (the account of the user in the device), with the Drive Api, that works fine
2 - the public google spreadsheet has a apps script inside with a simple function, i need to execute that function.
3 - the function in the apps script is executed excelent (with the ID of the script), with the Apps script api from android.
the problem is: each time is performed the copy of the spreadsheet, the script inside changes the ID, i need a way to get that ID always.
How to solve this ?

Although this is an old post, hopefully this is useful for anyone looking:
var scriptID = ScriptApp.getScriptId();
Source: Google Apps Script Services API

I had a similar problem. I solved it by doing the following;
IN THE SHEET THAT IS BEING COPIED
add a function to the sheet's script with the following code: function ScriptID(){return ScriptApp.getScriptId()}
In some cell add the formula =ScriptID()
access the value of that cell to retrieve the script ID.
Now, when you copy the original, the function and the formula will be copied with it. In the new sheet, the result of the formula will show the script id for that sheet
WARNING: This may present some security issues since now your sheet's script ID is exposed to anyone with read access to your sheet.
Hope this helps

As of the date of this post, there is no built-in, programmatic way to get the ID of the Apps Script project file bound to a Sheets file.
If that changes in the future, please comment below to let me know.
An existing feature request to add this capability is at the link below. Please click the star in the upper left hand corner.
https://issuetracker.google.com/issues/111149037
In reference to the answer about getting the ID by putting a function in a Sheets cell, putting a function in a Sheets cell that calls a function name in a "gs" file requires that you open the bound script file and enter the function. So, if you are going to do that, you could just manually get the Apps Script project file ID.
There is also no way to use the Drive API to list Apps Script project files that are bound to a document. The Drive API won't find an Apps Script files that are not shown in Drive.
The Google Drive API won't find Apps Script files that are not visibly shown in your Google Drive. So, the Drive API can't be used to get any information either. And the Apps Script API won't list all Apps Script files in your account. It will only get files by ID. So, you can only get one Apps Script file and you need to know the file ID.

Related

Firebase messaging - how to set Sender Id when requesting a token in Android?

How can I set the sender id when requesting a registration token for Firebase messaging in Android?
I need this, because I have to have different FB projects for the apps and the server that is sending the notifications. It's described here, but I think the doc is missing something. Searching StackOverflow results in answers that are not up-to-date, also. Can't find the way to do it with the latest version of the API.
I suggest having a read on controlling your Firebase registration/instance it also explains not only how to manually initialise your own firebase with custom options/name but also how firebase initialises itself automatically using the Google plugin and json file which will help you better understand what solution may be best for you.
Essentially you need to manually initialise your Firebase service in your Android apps Application class and provide a FirebaseOptions.Builder class to the Firebase.initializeApp, which allows you to call setGcmSenderId among other things like api key etc.
This official link shows how to configure mutliple projects in your application which may be an option too.
I wanted to keep using the google-services.json, so I didn't want to do the manual init. Then when I read how the Google Services Gradle Plugin works, I was going to make the manual init by using the values from the file - more info here: https://developers.google.com/android/guides/google-services-plugin#processing_the_json_file
In the end, I ended up not changing anything in the code and just changing project_info/project_number in the google-services.json. It's used for gcm_defaultSenderId. Everything looks good, now. Hope it's not used for anything, else. We are using FCM, only, so I think it will be ok. I don't like this, but it will do.
the sender id and project details are set using configuration file "google-services.json",it reads this file from app folder of your android project.
to get google-services.json for your firebase project in firebase console, open project settings and select your app and download the file and place it inside app folder of your android project.

Xamarin.Forms app need to write to a shared local storage location

I am in the process of writing a Xamarin.Forms line-of-business application.
The app will be targeting UWP and Android.
I have a requirement of being able to store information and pictures taken, in a shared folder on the local storage. This way, multiple users of the same device at different times can resume work-in-progress of the first user.
I am not sure what my options are, as I am unable to write outside of AppData folder (for UWP).
I read about potentially using a Picker and storing the selected folder in the FutureAccessList for UWP, but I am unsure if it will actually work and seems hacky as I will need to come up with a way of doing the same for Android at a later time.
Any ideas/pointers are greatly appreciated!
There is a special ApplicationData.SharedLocalFolder folder that allows you to share app data across user accounts on a PC. Its main limitation is that it requires appropriate Group Policy:
SharedLocalFolder is only available if the device has the appropriate group policy. If the group policy is not enabled, the device administrator must enable it. From Local Group Policy Editor, navigate to Computer Configuration\Administrative Templates\Windows Components\App Package Deployment, then change the setting "Allow a Windows app to share application data between users" to "Enabled."
I feel that the fact that this is not allowed by default is a great obstacle to the usefulness of this API.
There a publisher cache folder, but this solution is not appropriate for you because of documentation says:
Publisher Cache shares data across apps for the current user
So I would probably really go with the picker-based solution you proposed. Offer the user to select a folder to save the data to using the FolderPicker and then store the selected folder to the FutureAccessList. The future access list is reliable and can even track the changes of the selected item (like when the user moves it to a different location). The abstraction of the selection process in a cross-platform manner may be a bit more complicated, but it should be possible to hide it behind a dependency service implementation. My guess will provide an async method that will initialize the target location. On UWP this will check the FutureAccessList if a location was selected previously and if it was not, it will use the FolderPicker to let the user select it and will store it for future user afterward. On Android, it will work in Android specific manner (I am not sure what are the options there). Then the service will have some file manipulation methods that will abstract the platform-specific manipulation with the folder (I think you cannot use the common System.IO namespace, as you cannot directly access the user selected folder outside of the StorageFolder API)

Google Drive REST/Android API - Find Change-Set for a Drive Folder

My goal is to have a folder on the user's drive where he can drop files. My Android application should then detect (via polling) that a new file was created/uploaded in this folder on the drive and download it.
So far so good. I tried to do this with the Google Drive Android API, but I was given to understand that with the Google Drive Android API I do only have access to files created by my application. So if the user were to drop a photo in this folder via another device (e.g. desktop computer), I would not even see the file, let alone if it was newly created or not.
I was told that I could use the Google Drive REST API (v3) to extract the changes that happened since I last looked.
Drive.Changes.List request = drive.changes().list(startPageToken);
ChangeList changes = request.execute();
This does actually work. However, I have three problems with this approach:
I do get a list of changes containing all the files that changed on the drive. I do not, however, get a changeset. I do not know exactly what has changed. Was it a rename, creation, move, deletion, content change? I googled and I seem to be the only one wondering about this. How do I know what exactly changed?
As I described I would like to watch a single folder. How can I request the changes for only a single folder?
And finally: my application is using the native Google Drive Android API. So with adding this feature I suddenly need two APIs instead of one, even though I need one of them only for the simple task of polling for changes. What makes it even worse is that the user could in theory log into one API with one account, and into the other with another account. This does not make any sense. I get a lot of additional overhead and a critical functionality depends on the user logging in with the same account twice. Is there a solution to this problem?
I find it very frustrating that there are two Google Drive APIs avilable to begin with. You have to dig quite a bit to even get started and discover the exact difference if you know nothing initially. I still do not get the difference or why one of them is not capable to see files not created by itself.
You can try checking the documentation about Listening for Change Events:
You can use change listeners to receive notifications whenever a specified file or folder has changes to its contents or metadata. A change listener implements the ChangeListener interface for the ChangeEvent and receives a direct callback from the Drive service to a currently connected client application.
The following example code shows the logic you might implement to add a change listener to a file:
DriveFile file = Drive.DriveApi.getFile(mGoogleApiClient,
mSelectedFileId);
file.addChangeListener(mGoogleApiClient, changeListener);
In addition to adding the listener to the file or folder you wish to receive events for, your application must also implement the callback (changeListener in this example) you passed in the addChangeListener method call. The following demonstrates a callback that prints the received events to a log.
/**
* A listener to handle file change events.
*/
final private ChangeListener changeListener = new ChangeListener() {
#Override
public void onChange(ChangeEvent event) {
mLogTextView.setText(String.format("File change event: %s", event));
}
};
For callbacks that take action, such as retrieving the latest version, you can use the hasContentChanged and hasMetadataChanged methods to determine whether the file contents, metadata, or both have changed.
For a full working example, see the ListenChangeEventsForFilesActivity sample in the Google Drive Android API Demos app.
You can also check this related so question 22980497 for additional information.
Hope it helps!

Put some values on internet to access from android

In my app a user can (only) see the values uploaded by admin.
For example. A salesman is using the app will be able to see the latest rate provided by the manger to trade.
Now the question is "where to put these values?"
I have .net webservice experience with android but I guess it wont work in this scenario,will it?
Any suggestion that the returned result be in (preferably) XML format.
It sounds like you already know how to do this. You can download and parse xml within your app. If you alreayd know how to set up the websever, the rest is easy. Limiting who can see what is just a matter of associating specific transactions with an individuals account. Then just have the phone check for updates on that transaction when the app loads (using someting like AsyncTask) or if you want to get more complicated you could push notificatinos using the android cloud service, or even use a REST model. More details are needed for a more specific answer but you can do what you want.
You can do it on your own, and build a webserver with a MySQL/PHP JSON API or you can use parse.com for a smaller project.

Android application's exposed API or hooks

What is the best way to discover an Android application's API or hooks into/from the application?
Specifically, I am looking to pass a parameter or data to an application, utilize the application's specific functions, and return data or a parameter to the calling application.
A few ideas come to mind, but I am unfamiliar with what is available, specifically to Android.
Contact an application's developer directly
Somehow decompile the APK to browse the source
Read any available documentation
Some ways to check out what is available for :
Tool to re-engineer closed APK files
http://code.google.com/p/android-apktool/
Review intent filters for actions
Lookup the app in some sort of application manager on your phone. Android System Info. If you go to the details of the app it will tell you where the apk is and the name of it. For instance, under the Email app you can see "Source: /system/app/Email.apk".
To pull that off just do "adb pull /system/app/Email.apk Email.apk", to pull it to your current directory.
Look at the Manifest.xml. Rename the apk to zip and unpack.
Follow the instructions here: http://android.amberfog.com/?p=582
Then you can read the decompiled Manifest.xml and look at the intent filters they are registering.
Android applications are all in their own sandbox, so you can not just arbitrarily call some other Android applications' functions, they would need to be made public to you somehow.
If you are looking to execute some function that is provided by another Android application, you would most likely need to hear about it from the developer, most likely from their public documentation if they have any.
The correct way to do this is to use "intents". With an intent, you can launch another application (such as a barcode scanner) and the user interacts with it. Then, the application exits returning some data (such as the barcode). Try googling or see:
http://www.vogella.com/articles/AndroidIntent/article.html

Categories

Resources