Pause android app

2 posts, 0 answers
  1. Dzmitry
    Dzmitry avatar
    1 posts
    Member since:
    Feb 2014

    Posted 29 Mar 2014 Link to this post

    Hi,
    I need pause my android app (press home button programmatically). I have plugin with
    Home.java
    package org.apache.cordova.plugin.home;
     
    import org.json.JSONArray;
    import org.json.JSONException;
     
    import android.content.Intent;
     
    import org.apache.cordova.CallbackContext;
    import org.apache.cordova.CordovaPlugin;
     
    public class Home extends CordovaPlugin {
         
        @Override
        public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
            if (action.equals("goHome")) {
                try {              
                    Intent i = new Intent(Intent.ACTION_MAIN);
                    i.addCategory(Intent.CATEGORY_HOME);
                    cordova.getActivity().startActivity(i);
                } catch (Exception e) {
                    return false;
                }
                callbackContext.success();
                return true;
            }
            return false
        }
    }
    home.js
    cordova.define("cordova/plugin/home", function (require, exports, module) {
        var exec = require('cordova/exec');
        var Home = function() {};
     
        Home.prototype.goHome = function(successCallback, errorCallback) {
            return exec(successCallback, errorCallback, 'Home', 'goHome', []);
        };
        var home = new Home();
        module.exports = home;
    });
    and my plugin.xml
    <?xml version="1.0" encoding="UTF-8"?>
     
        id="org.apache.cordova.plugin.home.Home"
        version="0.1.0">
      <name>Home</name>
      <description>Cordova Homebutton Plugin</description>
      <license>Apache 2.0</license>
      <keywords>cordova,Home</keywords>
      <asset src="www/Home.js" target="Home.js" />
      <js-module src="www/Home.js" name="device">
        <clobbers target="window.Home" />
      </js-module>
      <!-- android -->
      <platform name="android">
        <config-file target="AndroidManifest.xml" parent="/manifest/application">
          <activity android:name="org.apache.cordova.plugin.home.Home"
              android:label="@string/app_name">
            <intent-filter>
              <action android:name="android.intent.action.MAIN" />
              <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
          </activity>
        </config-file>
        <config-file target="res/xml/config.xml" parent="/*">
          <feature name="Home">
            <param name="android-package" value="org.apache.cordova.plugin.home.Home"/>
          </feature>
        </config-file>
        <config-file target="AndroidManifest.xml" parent="/*">
          <uses-permission android:name="android.permission.WAKE_LOCK" />
        </config-file>
        <source-file src="src/android/Home.java" target-dir="src/org/apache/cordova/home/" />
      </platform>
    </plugin>
    and when I call 
    cordova.require('cordova/plugin/home').goHome(function () { 
                            console.log("Successfully launched home intent");
                        }, function () {
                            console.log("Error launching home intent");
                        }); 
    I get "Error launching home intent". This problem makes me crazy for several days. Can you help me?
  2. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 02 Apr 2014 Link to this post

    Hi Dzmitry,

    Thank you for reaching our forums.

    In order to import a custom plugin inside AppBuilder project, first make sure it meets the requirements. If it doesn't, you can check this article about making custom Cordova plugins, as well as our documentation about that matter.

    Further, I didn't find another way to pause the application on Android devices, apart from using custom plugin.

    I hope this helps.

    Regards,
    Kaloyan
    Telerik
     

    Share what you think about AppBuilder and Telerik Platform with us in our feedback portal, so we can become even better!

     
Back to Top