Gamemaker Studio android java extension not executing intent

1k views Asked by At

I'm making an extension to update the operating system that there's a new image file, it gets called by a function in GM:S like this:

osNotice(files+"/newButtonSkin.png");

Note that the variable files is the absolout path

then the function sends this as a string to the java class extension:

            package ${YYAndroidPackageName};//Import the GM:S stuff
    import ${YYAndroidPackageName}.R;
    import com.yoyogames.runner.RunnerJNILib;

    import android.app.Activity;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Environment;
    import android.util.Log;
    import java.io.File;
    import java.lang.String;


public class PickMe extends Activity {
    public final void osNotice(String fupdate)//Notify the OS that there's a new media file available
    {
        Log.i("yoyo", "New file to alert os-  "+fupdate);
        String canAlert = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(canAlert)) 

        {
        File file = new File(fupdate);
        Log.i("yoyo", "File ready to send- "+ fupdate);
        Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file));
        intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
        sendBroadcast(intent);
        Log.i("yoyo", "Updated sucessfully! "+fupdate);
        }
        else
        Log.i("yoyo", "Could not update file-  "+fupdate);
    }
}

in my manifest I have injected:

    <activity android:name=".PickMe"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Here's a screenshot of the log file when the game is run:

Runner Log file

The result of running the app is that the image is not updated to the os, Why isn't the intent being run? and why does the log say "can't find method on extension class: null" when I know the method is being run?

1

There are 1 answers

1
Wraithious On BEST ANSWER

Solved!! to make an intent visible to the Gamemaker: Studio side you have to call:

        RunnerActivity.CurrentActivity.sendBroadcast(intent);

after finalizing building the intent.This tells the gm:s side that the broadcast intent to the Media Scanner has started. thanks to Mool over at the GMC comunity for pointing this out to me!!

And to elaborate more, broadcast intents are different from other intents that start an activity, broadcast intents fire an async event on the java side of the extension, if you are starting an activity within your java file you would alert the jnilib of gm:s with

        RunnerActivity.CurrentActivity.startActivity(intent);

and also remembering to extend your class like:

public class MyClass extends Activity {// for either broadcast or start activity