我已经启动并运行了应用程序。推送通知工作正常。我需要当推送到达时,将应用程序带到前台,在 Android 上。所以,我发现的是这段代码:
Intent toLaunch = new Intent(getApplicationContext(), MainActivity.class);
toLaunch.setAction("android.intent.action.MAIN");
toLaunch.addCategory("android.intent.category.LAUNCHER");
摘自这个问题:用户单击主页按钮后将应用程序置于最前面 https://stackoverflow.com/questions/12074980/bring-application-to-front-after-user-clicks-on-home-button
我试图将此代码从 cordova 推送插件放入 GCMIntentService.java 中。无论我把它放在哪里,在编译时我总是会收到此错误:
/appdir/android/src/com/plugin/gcm/GCMIntentService.java:94: error: cannot find symbol
Intent toLaunch = new Intent(getApplicationContext(), MainActivity.class);
^
symbol: class MainActivity
location: class GCMIntentService
有什么想法如何从 cordova 插件 .java 文件访问这个“MainActivity.class”?
java编译器告诉你它不知道什么MainActivity.class
是在编译时GCMIntentService.java
。您必须导入MainActivity
来自定义它的包的类,例如如果包被调用cordovaExample
然后在顶部GCMIntentService.java
put
import cordovaExample.MainActivity;
并且该类必须声明为 public
package cordova;
public class MainActivity {
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)