有没有办法来监控和后台应用放大器;从用户看不见的 [英] is there a way to monitor application in background & invisible from user

查看:211
本文介绍了有没有办法来监控和后台应用放大器;从用户看不见的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是创建可以在没有用户交互来执行它的功能的应用程序。这不应该在网页的应用程序在设备的任何APPICON。安装后,用户并不需要知道应用程序运行的设备。我没有启动活动想在一个演示应用程序,但它不运行应用程序的code,这就是明显的。有没有办法来完成这个任务,这是否有什么意义?

What I want to do is to create an application which can perform it's feature without user interaction. This shouldn't have any appicon at Applications page in Device. After installation user don't need to aware of application running in device. I tried with No Launcher Activity in a Demo Application but it is not running code of application and that's obvious. Is there a way to accomplish this task, Does this make any sense?

推荐答案

是的,它是可能的,这让很多意义。但是这需要很多的事情要做,例如。

Yes it is possible, and it makes lot of sense. But it takes lot's stuff to do, for example.

1)。你需要让你的应用程序作为启动初创意味着无论何时用户重新启动移动设备或您的应用程序会自动开始运行的。

1). You need to make your app as boot start-up means whenever user restart mobile or device your app should automatically start's.

 <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <receiver android:name=".OnBootReceiver" >
            <intent-filter
                android:enabled="true"
                android:exported="false" >
                <action android:name="android.intent.action.USER_PRESENT" />
            </intent-filter>
        </receiver>
        <receiver android:name=".OnGPSReceiver" >
        </receiver>

2)。显然,你必须让应用程序没有,因为它是第一个活动发射模式,然后调用次活动不作为活动相关的服务。

2). Obviously you have to make app with no launcher mode as it's first activity and then call second activity as a service not as an activity.

所以基本上你必须创建这样的事情。

so basically you have to create something like this.

public class AppService extends WakefulIntentService{
       // your stuff goes here
}

和同时呼吁从mainActivity服务定义它是这样的。

and while calling service from your mainActivity define it like this.

Intent intent = new Intent(MainActivity.this, AppService.class);
startService(intent);
hideApp(getApplicationContext().getPackageName());

hideApp //用它在MainActivity之外。

hideApp // use it outside the mainActivity.

private void hideApp(String appPackage) {
        ComponentName componentName = new ComponentName(appPackage, appPackage
                + ".MainActivity");
        getPackageManager().setComponentEnabledSetting(componentName,
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
    }

3)。然后清单中定义该服务为像下面。

3). Then in manifest define this service as like below.

 <service android:name=".AppService" >
        </service>

修改

WakefulIntentService 是一个新的抽象类。请在下面检查。因此,创建一个新的Java文件并粘贴beloe code在里面。

WakefulIntentService is a new abstract class. Please check below. So create a new java file and paste the beloe code in it.

abstract public class WakefulIntentService extends IntentService {
    abstract void doWakefulWork(Intent intent);

    public static final String LOCK_NAME_STATIC = "test.AppService.Static";
    private static PowerManager.WakeLock lockStatic = null;

    public static void acquireStaticLock(Context context) {
        getLock(context).acquire();
    }

    synchronized private static PowerManager.WakeLock getLock(Context context) {
        if (lockStatic == null) {
            PowerManager mgr = (PowerManager) context
                    .getSystemService(Context.POWER_SERVICE);
            lockStatic = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                    LOCK_NAME_STATIC);
            lockStatic.setReferenceCounted(true);
        }
        return (lockStatic);
    }

    public WakefulIntentService(String name) {
        super(name);
    }

    @Override
    final protected void onHandleIntent(Intent intent) {
        doWakefulWork(intent);
        //getLock(this).release();
    }
}

这篇关于有没有办法来监控和后台应用放大器;从用户看不见的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆