Search Unity

Question Unity Android Plugin Activity not Found

Discussion in 'Android' started by Master_Zen, Jun 20, 2021.

  1. Master_Zen

    Master_Zen

    Joined:
    Apr 2, 2017
    Posts:
    20
    I'm currently trying to implement a notification system for an android game and need to open the app's native settings to help the user reenable the notification, when previosly turned off. I wrote a small andrid plugin and added it to the project.

    Code (Java):
    1. package com.example.plugin;
    2.  
    3. import android.app.Activity;
    4. import android.net.Uri;
    5. import android.content.*;
    6. import android.provider.Settings;
    7.  
    8. public class NotificationPlugin {
    9.     public void openSettings(Activity unityActivity) {
    10.          Intent i = new Intent(Settings.ACTION_APPLICATION_SETTINGS,
    11.             Uri.parse("package:" + unityActivity.getPackageName()));
    12.  
    13.         unityActivity.startActivity(i);
    14.     }
    15. }
    I added these lines to the custom AndroidManifest.xml in unity.

    Code (xml):
    1. <intent-filter>
    2.   <action android:name="android.settings.APPLICATION_SETTINGS" />
    3.   <category android:name="android.intent.category.DEFAULT" />
    4. </intent-filter>
    And i'm accessing the method in a c# wrapper class with this method.

    Code (CSharp):
    1. public static void OpenNotificationSettings() {
    2.     AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    3.     unityActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
    4.      
    5.     pluginClass = new AndroidJavaClass(pluginName);
    6.     pluginClass.Call("openSettings", unityActivity);
    7. }
    The variable `pluginName` is a constant string, containing the fully quialified package name of the plugin class.

    Using logcat i can see the follwing exception when trying to execute this:

    android.content.ActivityNotFoundException: No Activity found to handle Intent


    Since i have no real experiences with either android nor using plugins in unity, i don't know what to do with the exception and where the issue in all of these layers lies.
    Can anyone tell me how to fix this issue?

    PS: I know that i could probably have done this without a plugin, but there are other methods in the plugin, that i need and i wanted to have all native android related code packed into one plugin.