【问题标题】:Gamemaker Studio android java extension not executing intentGamemaker Studio android java扩展未执行意图
【发布时间】:2017-05-08 13:25:31
【问题描述】:

我正在做一个扩展来更新操作系统,有一个新的图像文件,它被 GM:S 中的一个函数调用,如下所示:

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

注意变量files是绝对路径

然后函数将其作为字符串发送到 java 类扩展:

            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);
    }
}

在我的清单中我已经注入:

    <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>

这是游戏运行时的日志文件截图:

运行app的结果是图片没有更新到os,为什么intent没有运行?当我知道方法正在运行时,为什么日志说“在扩展类上找不到方法:null”?

【问题讨论】:

    标签: java android extension-methods gml


    【解决方案1】:

    解决了!!要让 Gamemaker: Studio 看到意图,您必须调用:

            RunnerActivity.CurrentActivity.sendBroadcast(intent);
    

    在最终构建意图之后。这告诉 gm:s 方媒体扫描仪的广播意图已经开始。感谢 GMC 社区的 Mool 向我指出这一点!!

    更详细地说,广播意图与启动活动的其他意图不同,广播意图会在扩展的 java 端触发异步事件,如果您在 java 文件中启动活动,您会提醒 jnilib gm:s 与

            RunnerActivity.CurrentActivity.startActivity(intent);
    

    并且还记得扩展您的课程,例如:

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

    【讨论】:

    • 这正是我想要的!!
    猜你喜欢
    • 2022-08-08
    • 1970-01-01
    • 2021-04-08
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    • 1970-01-01
    • 2015-09-11
    相关资源
    最近更新 更多