Skip to content

Commit 58a35ef

Browse files
committed
permissionhelper plugin implemented
1 parent 5a176c3 commit 58a35ef

File tree

28 files changed

+884
-63
lines changed

28 files changed

+884
-63
lines changed

.github/workflows/debug_build.yml

+77-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,36 @@ jobs:
5050
name: pluginbasicutils-release
5151
path: pluginbasicutils/build/outputs/aar/pluginbasicutils-release.aar
5252

53+
54+
55+
- name: Upload debug pluginwebview
56+
uses: actions/upload-artifact@v1
57+
with:
58+
name: pluginwebview-debug
59+
path: pluginwebview/build/outputs/aar/pluginwebview-debug.aar
60+
61+
- name: Upload release pluginwebview
62+
uses: actions/upload-artifact@v1
63+
with:
64+
name: pluginwebview-release
65+
path: pluginwebview/build/outputs/aar/pluginwebview-release.aar
66+
67+
68+
69+
- name: Upload debug pluginpermissionhelper
70+
uses: actions/upload-artifact@v1
71+
with:
72+
name: pluginpermissionhelper-debug
73+
path: pluginpermissionhelper/build/outputs/aar/pluginpermissionhelper-debug.aar
74+
75+
- name: Upload release pluginpermissionhelper
76+
uses: actions/upload-artifact@v1
77+
with:
78+
name: pluginpermissionhelper-release
79+
path: pluginpermissionhelper/build/outputs/aar/pluginpermissionhelper-release.aar
80+
81+
82+
5383
- name: Create Release
5484
id: create_release
5585
uses: actions/create-release@v1
@@ -62,7 +92,9 @@ jobs:
6292
prerelease: false
6393
body: |
6494
What is new :
65-
- First Release
95+
- WebView and Permission Helper plugins added
96+
97+
6698
6799
- name: Release Upload pluginbasicutils-debug
68100
uses: actions/upload-release-asset@v1
@@ -83,3 +115,47 @@ jobs:
83115
asset_path: pluginbasicutils/build/outputs/aar/pluginbasicutils-release.aar
84116
asset_name: pluginbasicutils-release.aar
85117
asset_content_type: application/aar
118+
119+
120+
121+
- name: Release Upload pluginwebview-debug
122+
uses: actions/upload-release-asset@v1
123+
env:
124+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
125+
with:
126+
upload_url: ${{ steps.create_release.outputs.upload_url }}
127+
asset_path: pluginwebview/build/outputs/aar/pluginwebview-debug.aar
128+
asset_name: pluginwebview-debug.aar
129+
asset_content_type: application/aar
130+
131+
- name: Release Upload pluginwebview-release
132+
uses: actions/upload-release-asset@v1
133+
env:
134+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
135+
with:
136+
upload_url: ${{ steps.create_release.outputs.upload_url }}
137+
asset_path: pluginwebview/build/outputs/aar/pluginwebview-release.aar
138+
asset_name: pluginwebview-release.aar
139+
asset_content_type: application/aar
140+
141+
142+
143+
- name: Release Upload pluginpermissionhelper-debug
144+
uses: actions/upload-release-asset@v1
145+
env:
146+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
147+
with:
148+
upload_url: ${{ steps.create_release.outputs.upload_url }}
149+
asset_path: pluginpermissionhelper/build/outputs/aar/pluginpermissionhelper-debug.aar
150+
asset_name: pluginpermissionhelper-debug.aar
151+
asset_content_type: application/aar
152+
153+
- name: Release Upload pluginpermissionhelper-release
154+
uses: actions/upload-release-asset@v1
155+
env:
156+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
157+
with:
158+
upload_url: ${{ steps.create_release.outputs.upload_url }}
159+
asset_path: pluginpermissionhelper/build/outputs/aar/pluginpermissionhelper-release.aar
160+
asset_name: pluginpermissionhelper-release.aar
161+
asset_content_type: application/aar

.idea/gradle.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ Unity Android SDK Plugins is an Open Source project that contains code to genera
44

55
## Available Plugins :
66

7-
- pluginbasicutils - Provides basic Android util functions i.e. to show a toast, to check network connectivity [know more](/pluginbasicutils/README_PLUGINBASICUTILS.md)
7+
- pluginbasicutils : Provides basic Android util functions i.e. to show a toast, to check network connectivity [know more](/pluginbasicutils/README_PLUGINBASICUTILS.md)
8+
- pluginwebview : Provides android WebView implementation [know more](/pluginwebview/README_PLUGINWEBVIEW.md)
9+
- pluginpermissionhelper : Provides android permission helper functionality [know more](/pluginpermissionhelper/README_PLUGINPERMISSIONHELPER.md)
810

911
## Usage
1012

@@ -23,7 +25,7 @@ Check [build.gradle](build.gradle) for current config.
2325
### Request
2426
If you need an Android unity aar plugin create an issue with feature request or mail us at arupakamanstudios[AT]gmail[DOT]com.
2527

26-
### I prefer a star than a cup of coffee
28+
### I prefer a :star: than a cup of :coffee:
2729

2830
## Licensing
2931

app/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
id 'com.android.application'
33
id 'kotlin-android'
4+
id 'kotlin-parcelize'
45
}
56

67
android {
@@ -46,6 +47,7 @@ dependencies {
4647

4748
implementation project(':pluginbasicutils')
4849
implementation project(':pluginwebview')
50+
implementation project(':pluginpermissionhelper')
4951

5052

5153
testImplementation 'junit:junit:4.13.2'

app/src/main/AndroidManifest.xml

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.arupakaman.unitypluginsapp">
44

5+
<uses-permission android:name="android.permission.READ_CONTACTS" />
6+
<uses-permission android:name="android.permission.CALL_PHONE" />
7+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
8+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
9+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
10+
511
<application
612
android:allowBackup="true"
713
android:icon="@mipmap/ic_launcher"

app/src/main/java/com/arupakaman/unitypluginsapp/MainActivity.kt

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package com.arupakaman.unitypluginsapp
22

3+
import android.Manifest
34
import androidx.appcompat.app.AppCompatActivity
45
import android.os.Bundle
6+
import android.util.Log
57
import android.widget.Button
68
import android.widget.TextView
79
import com.arupakaman.pluginbasicutils.unity.UnityUtils
10+
import com.arupakaman.pluginpermissionhelper.ui.RequestPermissionActivity
811
import com.arupakaman.pluginwebview.WebViewActivity
12+
import org.json.JSONArray
13+
import org.json.JSONObject
914

1015
class MainActivity : AppCompatActivity() {
1116
override fun onCreate(savedInstanceState: Bundle?) {
@@ -30,7 +35,27 @@ class MainActivity : AppCompatActivity() {
3035
tvHello.text = result
3136
}
3237

33-
WebViewActivity.startWebViewActivity(this, "My GitHub Profile", "https://github.com/Noddy20", isToolbarEnabled = false)
38+
//WebViewActivity.startWebViewActivity(this, "My GitHub Profile", "https://github.com/Noddy20", isToolbarEnabled = false)
39+
40+
val json = JSONObject().apply {
41+
put("obj_name", "")
42+
put("unity_status_method_name", "abc")
43+
put("unity_info_method_name", "abc")
44+
put("handle_mandatory", true)
45+
put("handle_rational", true)
46+
put("permission_json_data", JSONArray().apply {
47+
put(JSONObject().apply {
48+
put("perm_name", Manifest.permission.ACCESS_FINE_LOCATION)
49+
put("perm_full_name", "Fine Location")
50+
})
51+
put(JSONObject().apply {
52+
put("perm_name", Manifest.permission.ACCESS_COARSE_LOCATION)
53+
put("perm_full_name", "Coarse Location")
54+
})
55+
})
56+
}
57+
Log.d("MainActivity", "startRequestPermission -> $json")
58+
RequestPermissionActivity.startRequestPermissionActivity(this, json.toString())
3459

3560
}
3661
}

pluginbasicutils/README_PLUGINBASICUTILS.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ This plugin provides basic Android util functions.
1919

2020
## Plugin Usage :
2121

22-
In your unity project, you can use these plugins in your C# scripts.
22+
In your unity project, you can use this plugins in your C# scripts.
23+
Download the plugin .aar file (pluginbasicutils-debug.aar or pluginbasicutils-release.aar based on development environment) from releases or
24+
build it by yourself and paste the .aar file in your Unity project's `Assets/Plugins/Android` directory. (Follow main README.md for plugin setup info)
2325

2426
### Common code required to access all functions
2527

2628
```
27-
const string pluginName = "com.arupakaman.pluginbasicutils.unity.UnityUtils"; // Constant of util static class location
29+
const string pluginName = "com.arupakaman.pluginbasicutils.unity.UnityUtils"; // Constant of util static class location
2830
2931
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
3032
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity"); // jo will be used for Context param

pluginpermissionhelper/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Unity Android SDK Plugin Permission Helper
2+
3+
This unity android plugin provides android permission helper to check permission (granted or not) and allow you to ask android permission/permissions for your Unity project.
4+
5+
## Plugin Functions/Features :
6+
7+
- Check if a specific permission is already granted to your app or not.
8+
- Allow you to request single/multiple permissions from user.
9+
- Callbacks can be used to receive permission granted or not with status only or with full information.
10+
11+
## Plugin Usage :
12+
13+
In your unity project, you can use this plugins in your C# scripts.
14+
Download the plugin .aar file (pluginpermissionhelper-debug.aar or pluginpermissionhelper-release.aar based on development environment) from releases or
15+
build it by yourself and paste the .aar file in your Unity project's `Assets/Plugins/Android` directory. (Follow main README.md for plugin setup info)
16+
17+
### Common code required to access all functions
18+
19+
```
20+
const string pluginName = "com.arupakaman.pluginpermissionhelper.ui.RequestPermissionActivity"; // Constant of RequestPermissionActivity class location
21+
22+
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
23+
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity"); // jo will be used for Context param
24+
AndroidJavaClass ajcPermissionHelper = new AndroidJavaClass(pluginName); // ajcWebView will be used to access WebViewActivity class
25+
```
26+
### To Check if Permission is Granted or not
27+
28+
Below function returns true if permission is already granted.
29+
30+
```
31+
bool isGranted = ajcPermissionHelper.CallStatic<bool>(
32+
"hasPermission", // function name to check permission
33+
jo, // first param context defined above
34+
"android.permission.ACCESS_FINE_LOCATION", // Permission name constant String [see more](https://developer.android.com/reference/android/Manifest.permission#constants)
35+
);
36+
37+
```
38+
39+
### To Request Permission/Permissions
40+
41+
```
42+
// Note* : below variable jsonPermissionData is not in correct String format, make sure you create your json in String
43+
String jsonPermissionData = {
44+
"obj_name": "Name of the Object the Unity Script is attached to",
45+
"unity_status_method_name": "methodToReceivePermissionStatus with a String param",
46+
"unity_info_method_name": "methodToReceivePermissionDetailedInfo with a String param", // you can also use one of the callback method unity_status_method_name or unity_info_method_name
47+
"handle_mandatory": "true/false to handle mandatory permission dialog in plugin (Optional, by default true)",
48+
"handle_rational": "true/false to handle mandatory permission dialog in plugin (Optional, by default true)",
49+
"permission_json_data": [
50+
{
51+
"perm_name": "android.permission.ACCESS_FINE_LOCATION", //Use Constant values [from here](https://developer.android.com/reference/android/Manifest.permission#constants)
52+
"perm_visible_name": "Location Permission", // Name that will be visible to user in mandatory/rational dialogs
53+
"is_mandatory": "true/false // true if permission is mandatory (Optional, by default true)"
54+
}
55+
]
56+
}
57+
58+
ajcPermissionHelper.CallStatic(
59+
"startRequestPermissionActivity", // function name to launch Permission request Activity
60+
jo, // first param context defined above
61+
jsonPermissionData // json as String with permission and callback information
62+
);
63+
64+
65+
// A valid jsonPermissionData variable example:
66+
String jsonPermissionData = "{\"obj_name\": \"Text\", \"unity_status_method_name\": \"PermissionGrantedStatus\", \"unity_info_method_name\": \"PermissionGrantedInfo\", \"handle_mandatory\": \"true\", \"handle_rational\": \"true\",\"permission_json_data\": [{\"perm_name\": \"android.permission.ACCESS_FINE_LOCATION\", \"perm_visible_name\": \"Location Permission\", \"is_mandatory\": \"true\"}]}"
67+
68+
```
69+
70+
### To receive permission request status callback
71+
72+
You can use one of the below methods or both of them :
73+
74+
1) You can implement a method with a String parameter to receive the overall permission status. This method will receive status in the String parameter with one of the below values :
75+
GRANTED (If user has granted all the mandatory permissions)
76+
NOT_GRANTED (If user has not granted any one of the mandatory permissions)
77+
SHOW_RATIONAL (If user has selected not to ask again for a mandatory permission)
78+
79+
Status response example = {"status":"GRANTED"}
80+
Send this method name in json key = "unity_status_method_name"
81+
82+
2) You can implement a method with a String parameter to receive the complete permission status information. This method will receive a json object with status of all requested permissions and other data as follows:
83+
84+
Example response = [{"perm_name":"android.permission.ACCESS_FINE_LOCATION","perm_visible_name":"Location Permission","is_mandatory":true,"is_granted":true}]
85+
Send this method name in json key = "unity_info_method_name"
86+
87+
You can parse the response and use the keys to check which permission is granted and which is not.
88+
89+
### Customize dialog Strings
90+
91+
Override the below string resource in your Unity project to customize the error message :
92+
93+
```
94+
<!-- Override these strings in your Unity project to customize the dialog text -->
95+
96+
<string name="dialog_message_rational">You need to grant required permission from device settings :</string>
97+
<string name="dialog_action_rational_positive">Grant Now</string>
98+
<string name="dialog_action_rational_negative">Not Now</string>
99+
<string name="dialog_message_perm_mandatory">You need to grant required permission :</string>
100+
<string name="dialog_action_perm_mandatory">Okay</string>
101+
```
102+
103+
### I prefer a :star: than a cup of :coffee:

pluginpermissionhelper/build.gradle

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
plugins {
2+
id 'com.android.library'
3+
id 'org.jetbrains.kotlin.android'
4+
id 'kotlin-parcelize'
5+
}
6+
7+
android {
8+
compileSdk compileTargetSDK
9+
10+
defaultConfig {
11+
minSdk 17
12+
targetSdk compileTargetSDK
13+
14+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15+
consumerProguardFiles "consumer-rules.pro"
16+
}
17+
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
compileOptions {
25+
sourceCompatibility JavaVersion.VERSION_1_8
26+
targetCompatibility JavaVersion.VERSION_1_8
27+
}
28+
kotlinOptions {
29+
jvmTarget = '1.8'
30+
}
31+
}
32+
33+
dependencies {
34+
//Use compileOnly otherwise will throw error
35+
compileOnly fileTree(dir: "libs", include: ["*.jar"])
36+
37+
implementation 'androidx.core:core-ktx:1.7.0'
38+
implementation 'androidx.appcompat:appcompat:1.4.1'
39+
implementation 'com.google.android.material:material:1.5.0'
40+
41+
testImplementation 'junit:junit:4.13.2'
42+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
43+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
44+
}

pluginpermissionhelper/consumer-rules.pro

Whitespace-only changes.
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

0 commit comments

Comments
 (0)