# Call java plugin method in unity

**URL:** https://discussions.unity.com/t/call-java-plugin-method-in-unity/827042
**Category:** Mobile
**Tags:** Android
**Created:** [February 2, 2021, 12:07pm UTC](https://discussions.unity.com/t/call-java-plugin-method-in-unity/827042 "2021-02-02T12:07:02Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![qkrwlgp7827](https://avatars.discourse-cdn.com/v4/letter/q/e495f1/32.png) [@qkrwlgp7827](https://discussions.unity.com/u/qkrwlgp7827)
#### Post date: [February 2, 2021, 12:07pm UTC](https://discussions.unity.com/t/call-java-plugin-method-in-unity/827042/1 "2021-02-02T12:07:02Z")

</div>

Hi I’m trying to use login plugin for Unity. I put java files in Unity and customized AndroidManifest and build.gradle.

Build is success, but there’s a problem. I want that when I click the button, call “CallAndroid” method in java. BUT…Nothing happens. I export this and open in Android Studio, but nothing message in Logcat.  
I’m a beginner so I don’t know what should I do. ☹ Please Help me!!!

**This is Unity code**

```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Login : MonoBehaviour
{
    AndroidJavaClass unityClass;
    AndroidJavaObject unityActivity;
    AndroidJavaObject unityContext;
    AndroidJavaClass plugin;

    private void Awake()
    {
        //Get Unity Context
        unityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        unityActivity = unityClass.GetStatic<AndroidJavaObject>("currentActivity");
        unityContext = unityActivity.Call<AndroidJavaObject>("getApplicationContext");

        plugin = new AndroidJavaClass("com.company.example.javaPlugin");
    }

    public void NavLogin()
    {
        plugin.Call("CallAndroid", unityContext);
    }
}

```

**And this is Java code**

```javascript
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.content.Context;

import com.unity3d.player.UnityPlayer;
import com.unity3d.player.UnityPlayerActivity;

public class javaPlugin extends UnityPlayerActivity {

private Context mContext;

@Override
protected void onCreate(Bundle savedInstanceState)
{
Log.d("#####", "onCreate()");
super.onCreate(savedInstanceState);

}

public void CallAndroid(Context context)
{
this.mContext = context;
Log.d("#####", "CallAndroid()");

Intent loginIntent = new Intent(this, naverLogin.class);
context.startActivity(loginIntent);
     
}

@Override
public void onBackPressed() {
Log.d("#####", "onBackPressed()");
//super.onBackPressed();
}
}

```

---

<div class="post-metadata">

### Author: ![Aurimas-Cernius](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@Aurimas-Cernius](https://discussions.unity.com/u/Aurimas-Cernius)
#### Post date: [February 2, 2021, 1:12pm UTC](https://discussions.unity.com/t/call-java-plugin-method-in-unity/827042/2 "2021-02-02T13:12:13Z")

</div>

In order to call CallAndroid() you need an object, not class.  
If this class is used as activity in your application, then the unityActivity variable will have an instance of your class, so you can call that method on it directly. You can also remove the call to getApplicationContext from C# code and call it directly in Java code.

---

<div class="post-metadata">

### Author: ![qkrwlgp7827](https://avatars.discourse-cdn.com/v4/letter/q/e495f1/32.png) [@qkrwlgp7827](https://discussions.unity.com/u/qkrwlgp7827)
#### Post date: [February 3, 2021, 8:11am UTC](https://discussions.unity.com/t/call-java-plugin-method-in-unity/827042/3 "2021-02-03T08:11:50Z")

</div>

> [@Aurimas-Cernius](#):
>
> In order to call CallAndroid() you need an object, not class.  
> If this class is used as activity in your application, then the unityActivity variable will have an instance of your class, so you can call that method on it directly. You can also remove the call to getApplicationContext from C# code and call it directly in Java code.

Thank you for your answer. I solved my problem by referring to your answer!!!

---

<div class="post-metadata">

### Author: ![testlap46123](https://avatars.discourse-cdn.com/v4/letter/t/d78d45/32.png) [@testlap46123](https://discussions.unity.com/u/testlap46123)
#### Post date: [November 7, 2022, 5:40am UTC](https://discussions.unity.com/t/call-java-plugin-method-in-unity/827042/4 "2022-11-07T05:40:34Z")

</div>

Hello [qkrwlgp7827](https://forum.unity.com/members/qkrwlgp7827.6716324/) , if you could please post your updated code for my reference, it would be appreciated very much.  
Thanks
