Git Repositories

Restart Plugin... to test
authorCyrille Pontvieux <jrd@enialis.net>
Mon, 3 Nov 2014 16:00:03 +0000 (17:00 +0100)
committerCyrille Pontvieux <jrd@enialis.net>
Mon, 3 Nov 2014 16:00:03 +0000 (17:00 +0100)
AUTHORS [new file with mode: 0644]
LICENSE.md [new file with mode: 0644]
plugin.xml [new file with mode: 0644]
src/android/net/enialis/cordova/RestartPlugin.java [new file with mode: 0644]
www/RestartPlugin.js [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..5823b1f
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+Cyrille Pontvieux <cyrille@enialis.net>
diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644 (file)
index 0000000..304115c
--- /dev/null
@@ -0,0 +1,47 @@
+# Licenses
+
+## Common Javascript
+
+MIT or Apache 2.0
+
+## Android version
+
+MIT or Apache 2.0
+
+- Extracted from DroidGap by @brodybits (Chris Brody)
+- Transaction batch processing of Android version by @marcucio
+- Maintained by @brodybits (Chris Brody)
+
+## iOS version
+
+MIT only
+
+## WP version
+
+MIT or Apache 2.0
+
+## DLLs for WP version
+
+### Newtonsoft.Json.dll: Json.NET
+
+MIT License
+
+Copyright (c) 2007 James Newton-King
+
+### SQLiteWPNative.DLL: C#-SQLite
+
+MIT License
+
+C#-SQLite is an independent reimplementation of the SQLite software library.
+SQLite® is a registered trademark of Hipp, Wyrick & Company, Inc.
+
+The overall C#-SQLite package is distributed under the terms of the MIT License, given below.  Some parts are distributed under more permissive licenses, see individual source files for details.
+
+Copyright (c) 2009-2012 Noah Hart and others, see individual source files for details.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
diff --git a/plugin.xml b/plugin.xml
new file mode 100644 (file)
index 0000000..06bc877
--- /dev/null
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    id="net.enialis.cordova.restartPlugin"
+    version="1.0.0">
+
+    <name>RestartPlugin</name>
+
+    <license>MIT</license>
+
+    <description>Restart your application</description>
+    <author>Cyrille Pontvieux</author>
+
+    <engines>
+        <engine name="cordova" version=">=3.3.0" />
+    </engines>
+
+    <js-module src="www/RestartPlugin.js" name="RestartPlugin">
+        <clobbers target="RestartPlugin" />
+    </js-module>
+
+    <!-- android -->
+    <platform name="android">
+        <source-file src="src/android/net/enialis/cordova/RestartPlugin.java" target-dir="src/net/enialis/cordova"/>
+    </platform>
+</plugin>
diff --git a/src/android/net/enialis/cordova/RestartPlugin.java b/src/android/net/enialis/cordova/RestartPlugin.java
new file mode 100644 (file)
index 0000000..9b66333
--- /dev/null
@@ -0,0 +1,53 @@
+package net.enialis.cordova
+
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.Intent;
+import android.util.Log;
+
+import java.util.Random;
+
+import org.apache.cordova.CallbackContext;
+import org.apache.cordova.CordovaPlugin;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+public class RestartPlugin extends CordovaPlugin {
+       
+       private final static String RESTART_COMMAND = "restart";
+       
+       @Override
+       public boolean execute(String actionAsString, JSONArray args, CallbackContext cbc) {
+               if (RESTART_COMMAND.equals(actionAsString)) {
+                       Log.i(getClass().getSimpleName(), "restart asked from Cordova");
+                       final Context ctx = cordova.getActivity();
+                       final PackageManager pm = c.getPackageManager();
+                       // check if we got the PackageManager
+                       if (pm == null) {
+                               Log.e(getClass().getSimpleName(), "No PackageManager");
+                               return false;
+                       }
+                       // create the intent with the default start activity for your application
+                       final Intent startActivity = pm.getLaunchIntentForPackage(c.getPackageName());
+                       if (startActivity == null) {
+                               Log.e(getClass().getSimpleName(), "No launch activity");
+                               return false;
+                       }
+                       startActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+                       // create a pending intent so the application is restarted after System.exit(0) was called.
+                       // We use an AlarmManager to call this intent in 100ms
+                       final int pendingIntentId = new Random().nextInt();
+                       final PendingIntent pendingIntent = PendingIntent.getActivity(c, pendingIntentId, startActivity, PendingIntent.FLAG_CANCEL_CURRENT);
+                       final AlarmManager mgr = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE);
+                       mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, pendingIntent);
+                       // kill the application
+                       System.exit(0);
+                       return true;
+               }
+               return false;
+       }
+}
diff --git a/www/RestartPlugin.js b/www/RestartPlugin.js
new file mode 100644 (file)
index 0000000..23fcc25
--- /dev/null
@@ -0,0 +1,7 @@
+(function() {
+       this.restartPlugin = {
+               restart: function() {
+                       cordova.exec(function() {}, function() {}, "RestartPlugin", "restart", []);
+               }
+       };
+}).call(this);