Start application in background on bootup - android

I would like to start my application when the phone boots up. But the user should not know that the application has started. I am doing the boot up by receiving the BOOT_COMPLETE event in a broadcast receiver and am able to minimize the application by using moveTaskToBack(true).
But my application is visible for a split second before it gets minimized and I do not want this to happen. My application does not have any services. Is there any way in which I can start the application minimized without the end user noticing ?
Thanks

enter code here
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
public class BootUpReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, MyActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}

Related

how to make my service work when user open the mobile

I want to make my service always working but in the normal service if the user close the phone and open it or restart it the service is stoping can you help me. thanks
You could use a Broadcast Receiver that would take the permission to broadcast a message on the restart of the phone that would tell the service to be started or as we call it in technical terms we would use an intent-filter having the action of starting the service when in the actions (or the ) the boot process is completed.
In manifest file :-
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
In application tag of manifest.xml :-
<receiver android:name="com.example.MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
In MyBroadcastReceiver.java :-
package com.example;
public class MyBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent startServiceIntent = new Intent(context, MyService.class);
context.startService(startServiceIntent);
}
}
Now, at the end the service class of MyService would be started by this boradcasting.

How to start an application automatically after opening a lock Screen in android?

I want to build an application which will start automatically after lock screen of android mobile. Where can I get more Info about lock screen and home screen of android mobile?
Create a broadcast receiver that detects the screen coming on. Have it launch your activity. Then when the lock screen is dismissed, your activity will be on top.
See source code of mylockforandroid
https://code.google.com/p/mylockforandroid/source/browse/
and you will need use
DeviceAdminReceiver
http://developer.android.com/reference/android/app/admin/DeviceAdminReceiver.html
for disableing default android screenlock.
for starting your activity when user unlock screen register an Intent.ACTION_SCREEN_ON and Intent.ACTION_SCREEN_OFF as:
add this code in manifast.xml register ScreenReceiver as:
<receiver android:name=".ScreenReceiver">
<intent-filter>
<action android:name="android.intent.action.SCREEN_OFF"/>
<action android:name="android.intent.action.SCREEN_ON"/>
</intent-filter>
</receiver>
and add an ScreenReceiver.java as:
public class ScreenReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_ON))
{
Intent intent = new Intent();
intent.setClass(context, ScreenLockActivity.class);
startActivity(intent);
}

BroadcastReceiver doesn't work

I added receiver in manifest
<receiver android:name=".PackageReceiver"
android:enabled="true">
<intent-filter android:priority="100">
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REPLACED"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
And this is my BroadcastReceiver
public class PackageReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
Log.e("noti", "sucess");
//Start Notification Service
Intent i = new Intent(context, NotificationService.class);
context.startService(i);
}}
..
When I install this package, It's didn't work...
This package don't have activity.(only service and resource)
Is this a problem?
Then..
How to call BroadcastReceiver in this package without activity?
This is a question that is asked a lot.
Check out this Commonsware blog.
Starting with 3.1 when applications are installed they are in a “stopped” state so they will not be able to run until the user explicitly launches them. Pressing Force Stop will return them to this state.
There needs to be an active component in your application that the user can start. When your activity gets started, your BroadcastReceiver will be registered.
You have just declared and implemented a BroadcastReceiver, but you haven't started it yet, you need an entry point to start your receiver ( activity or service )
here is the code to register
PackageReceiver packageReceiver= new PackageReceiver(this);
registerReceiver( packageReceiver, new IntentFilter("android.intent.action.PACKAGE_ADDED"));

Start app on device boot, but not run service

I have a BroadcastReceiver that is using the BOOT_COMPLETED intent-filter in the AndroidManifest, which then runs my Service when the device boots. Is it possible to have my Service start, but not actually run the code in the Service? I have an AlarmManager that run the Service at a regular interval, but, ideally, I'd like that code to not run when the device starts.
<receiver android:name="com.app.AlarmReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Yes, call startActivity:
#Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent();
i.setClassName("com.test", "com.test.MainActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}

how to lauch an 3rd application automatically when the android phone is switched on

can any one tell me "how to lauch an 3rd application automatically when the android phone is switched on?". As I want to launch an application which is written by me when the device is turned on.
I will be waiting for any valuable reply .
Thanks in Advance,
you need an implementation of BroadcastReceiver, which is intended on BOOT_COMPLETED action. Like this:
public class OnStartReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Runtime.getRuntime().exec("your command");
// but it is better here to do that:
Intent myIntent = new Intent(context, YourActivity.class);
context.startActivity(myIntent);
}
}
Also, you should add receiver tag to your manifest file with android:name = your fully qualified name of OnStartReceiver and intent-filter tag nested with BOOT_COMPLETED as intent name, like this:
<receiver android:name=".onStartReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver >

Categories

Resources