【发布时间】: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