Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Added iOS and Android Azure Storage Samples #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Examples/AzureStorage/Android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*.iml
.gradle
/local.properties
/.idea/caches/build_file_checksums.ser
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
.DS_Store
/build
/captures
.externalNativeBuild

/.gradle/
/.idea/
/gradle/
app/libs/
44 changes: 44 additions & 0 deletions Examples/AzureStorage/Android/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
##Microsoft Azure Mobile Android Upload Blob Sample
##Introduction

Azure Storage is a Microsoft-managed service providing cloud storage that is highly available, secure, durable, scalable, and redundant. Azure Storage includes Azure Blobs (objects), Azure Data Lake Storage Gen2, Azure Files, Azure Queues, and Azure Tables.
This application demonstrates an image upload to blob storage.

##Summary
This app uploads frames as seen by the device's camera to Microsoft Azure Storage. The app operates in capture mode and frame by frame capture mode. In capture mode it uploads a single photo taken from the device. In frame by frame capture mode it uploads frames seen by the camera every 1 seconds for next 20 seconds.

![ScreenShot](screenshots/app_screenshot.png)
##Prerequisite

1. Android Studio
2. A device with camera
3. An Azure Account

###Server setup
1. Login to [Azure Portal](https://portal.azure.com/#home).
2. Select **Storage Account**

![left menu](screenshots/leftmenu.png)

3. Click + to add storage account.

![add](screenshots/add.png).

4. You have to add the blob container to organize the files. You can do that by clicking on ```Home->Storage Accounts->'Storage Account Name'->Blob service->Blobs```

![blobs](screenshots/blob.png)

Now your Azure portal is ready to store images.

##Before Running Application

Please assign following values in application
1. Assign the values of your bucket name ```public static final String BUCKET_NAME = "***" ``` in Constant.java
2. Chnage the value of ``` private static final String STORAGE_CONNECTION_STRING ="***"``` with appropriate value in StorageProvider.java

You can get connection string from here
![connection string](screenshots/accesskey.png)




2 changes: 2 additions & 0 deletions Examples/AzureStorage/Android/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
/build/
31 changes: 31 additions & 0 deletions Examples/AzureStorage/Android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.yml.azureimageupload"
minSdkVersion 24
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'

implementation 'com.mindorks:paracamera:0.2.2'

implementation "com.microsoft.azure.android:azure-storage-android:${rootProject.azureStorageAndroid}"
implementation 'com.orhanobut:logger:2.2.0'
implementation 'com.android.support:design:28.0.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.0'
}
21 changes: 21 additions & 0 deletions Examples/AzureStorage/Android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.yml.azureimageupload;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.yml.azureimageupload", appContext.getPackageName());
}
}
65 changes: 65 additions & 0 deletions Examples/AzureStorage/Android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
The MIT License (MIT)

Copyright © 2019 YML. All Rights Reserved.

Permission is hereby granted, free of charge,
to any person obtaining a copy of this software and
associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject
to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.yml.azureimageupload">

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".AzureApp"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning"
tools:replace="android:allowBackup">
<service
android:name=".service.PictureUploadIntentService"
android:exported="false"/>

<activity android:name=".activity.AlphabetDetectorActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* The MIT License (MIT)
*
* Copyright © 2019 YML. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/


package com.yml.azureimageupload;

import android.app.Application;

import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.Logger;

public class AzureApp extends Application {
@Override
public void onCreate() {
super.onCreate();
Logger.addLogAdapter(new AndroidLogAdapter());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

/*
* The MIT License (MIT)
*
* Copyright © 2019 YML. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/

package com.yml.azureimageupload.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.yml.azureimageupload.R;
import com.yml.azureimageupload.fragment.Camera2Fragment;

public class AlphabetDetectorActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alphabet_detector);
if (null == savedInstanceState) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, Camera2Fragment.newInstance())
.commit();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* The MIT License (MIT)
*
* Copyright © 2019 YML. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
package com.yml.azureimageupload.azure;

import com.microsoft.azure.storage.CloudStorageAccount;
import com.microsoft.azure.storage.blob.CloudBlobClient;

import java.net.URISyntaxException;
import java.security.InvalidKeyException;

public class StorageProvider {
private static final String STORAGE_CONNECTION_STRING = "SET YOUR VALUE HERE";

private static StorageProvider storageProvider;

private CloudBlobClient cloudBlobClient;

private StorageProvider() {
try {
final CloudStorageAccount storageAccount = CloudStorageAccount
.parse(STORAGE_CONNECTION_STRING);
cloudBlobClient = storageAccount.createCloudBlobClient();

} catch (URISyntaxException | InvalidKeyException e) {
e.printStackTrace();
}
}

public static synchronized StorageProvider getInstance() {
if (storageProvider == null) {
storageProvider = new StorageProvider();
}
return storageProvider;
}

public CloudBlobClient getCloudBlobClient() {
return cloudBlobClient;
}

}
Loading