Unity Android Plugin onActivityResult not called
I am writing a plugin for Android in Android Studio and running it in Unity 5.6. I have a created a class for selecting images - however, when the user selects an image, the "Gallery" app opens . Here is my code:
fotoSec.java
package com.alptugrul.background;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.provider.MediaStore;
import android.widget.Toast;
import com.unity3d.player.UnityPlayer;
import com.unity3d.player.UnityPlayerActivity;
/**
* Created by Alpaslan on 25.3.2018.
*/
public class fotoSec extends UnityPlayerActivity {
static Uri imgUri;
public static void fotoSece() {
Activity activity = UnityPlayer.currentActivity;
Intent gallery = new Intent(Intent.ACTION_GET_CONTENT, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
activity.startActivityForResult(gallery, 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Toast.makeText(UnityPlayer.currentActivity.getApplicationContext(), "bnhg", Toast.LENGTH_SHORT).show();
}
public static String getURL () {
String url = null;
if (imgUri != null){
url = imgUri.toString();
}
return url;
}
}
imgSec.cs in Unity,
using UnityEngine;
public class imgSec : MonoBehaviour {
private static string fullClassName = "com.alptugrul.background.fotoSec";
AndroidJavaClass fotoSecClass;
private void Start() {
fotoSecClass = new AndroidJavaClass(fullClassName);
}
public void fotoSec() {
fotoSecClass.CallStatic("fotoSece");
}
}
Manifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alptugrul.background">
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:label="@string/app_name">
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:launchMode="singleTask"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
<activity android:name=".fotoSec">
<intent-filter>
<action android:name="android.intent.action.PICK"/>
<action android:name="android.intent.action.GET_CONTENT"/>
</intent-filter>
</activity>
<receiver android:name=".Baslangic"
android:enabled ="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
</receiver>
</application>
</manifest>
When running app, I hit the button and the gallery opens. I then select an image from but after selecting, there is no Toast message which I added in the onActivityResult function.
Thanks..
Comment