我正在为Android开发混合Phonegap应用程序.该应用程序只使用我正在开发的一个插件.这个插件做了三件事
我已经实现了代码以使应用程序调整到设备重新启动时有些惶恐,但结果很简单(感谢我在SO上的其他线程中找到的信息)
package com.example.plugin;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaWebView;
import android.content.Context;
import android.content.BroadcastReceiver;
import android.content.pm.PackageManager;
import android.app.Activity;
import android.content.Intent;
public class Rebooter extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Intent i = new Intent(context, MyAppCordovaPlugin.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
Run Code Online (Sandbox Code Playgroud)
我这样注册了重启接收器
<receiver android:enabled="true" android:name=".Rebooter"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
MyAppCordovaPlugin是我的应用程序/插件的入口点 - 扩展CordovaPlugin该类的插件.这是我在那里做的
public class MyAppCordovaPlugin extends CordovaPlugin
{
private …Run Code Online (Sandbox Code Playgroud)