Sample on Workflow of Forge Viewer by Android Studio
- NOTE:
- 1. This sample was programmed on Eclipse + ADT. Now it is migrated to Android Studio
- Please get the old commit if you still need the version of Eclipse + ADT.
- 2. Demo APK is not provided as it would ask the user to store customer's model in the author's bucket of Forge
- which does not apply to the compliance of data protection. So,please build the sample with your own
- credential and produce the APK
This is a sample for Android devices demoing how to translate 2D/3D file by Forge platform, and view them in the browser of mobile.
- Get an access token by [Forge Authentication API] (https://developer.autodesk.com/en/docs/oauth/v2)
- Create a bucket by Forge Data Management API
- Upload a 2D/3D design file / model by Forge Data Management API
- Post a job to translate the model to the Forge Viewer format by Forge Model Derivative API
- Download the model thumbnail by Forge Model Derivative API
- Display the model in your browser by the workflow of Forge Viewer
- Install [Adroind Studio] (https://developer.android.com/studio/index.html/) and the neccesary API SDK. In this test, Android API SDK version 28 is installed.
- Download and build Forge library by Forge JAVA SDK. Copy all * .jar (except httpcore-4.4.1.jar and httpclient-4.5.jar) in the target>>lib folder to app>>lib folderof this sample. For convenience, these .jar are already included in the project. However please syncronize with Forge JAVA SDK if it has new commits.
- Make sure to provide test models in the extension storage of the emulator or physical mobile. To copy a file to emulator, Android Device Monitor can be used. Or, copy by adb in command line. A test model has been provided at demomodel/RevitNative.rvt.
- Visit the Forge Developer Portal, sign up for an account, then create an app.Copy API key and secret to line 15 and line 16 in Global.java
- Build the app and fix any errors
- Open the App on android device or emulator, click [Get Token] >> token should appear in the text box.
- Input bucket name in text near box under [create bucket], click [Create Bucket] >> wait for the success info. The bucket key (i.e. bucket name) must match “^[-_.a-z0-9]{3,128}$”. That is bucket must be between 3 to 128 characters long and contain only lower-case letters, numbers and the symbols . _ –. And bucket keys must be unique within the data center or region in which they were created. Best practice is to incorporate your company name/domain name or the client Id into the bucket name. If you prefer to use the client Id(should convert to lower-case first) as part of bucket name, please note that it is the consumer key, not the secret key. Please also pay attention to the length of the whole bucket name, which should be less than 128.
- Click [Browser Model] to show available test file list, choose one of them
- Click [Upload Model] to upload the model file, the URN appears in the text box once file is uploaded.
- Click [Post Job] to send a job to translate the model, status shows up in text box.
- Once the translation status is completed, click [Show thumbnail] to get the thumbnail and display it in the image box blow. You may see "get thumbnail failed" if translation is still not in progress, you can try again latter.
- Click [Launch Viewer] to launch the viewer in a WebGL enabled browser. The code taks advantage of a demo website by inputing the token and urn, then the demo website will launch the viewer. the workflow could be repalced with any other demo website or your own website if it follows the format that inputs token and urn. It is tested on the default browser of the device. If you have problems with this step, you can look into console of browser with USB debugging.
This sample is licensed under the terms of the MIT License. Please see the LICENSE file for full details.
Xiaodong Liang
Developer Advocate
Autodesk Forge Partner Development