I have an application that I would like to have automatically start following boot completion. The following code seems overly complicated and I get erratic application starts when swiping to a neighbouring workspace.
What am I missing here? I have an activity class, a service class, as well as a broadcast receiver. Below is my code (in that order) followed by the manifest.
public class BlueDoor extends Activity implements OnClickListener{
Button btnExit;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.main);
btnExit = (Button) this.findViewById(R.id.ExitButton);
btnExit.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.ExitButton:
System.exit(0);
break;
}
}
}
service.class
public class BlueDoorStartService extends Service {
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onCreate() {
super.onCreate();
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
callIntent.setClass(this, BlueDoor.class);
startActivity(callIntent);
// do something when the service is created
}
}
broadcast receiver
public class StartBlueDoorAtBootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent serviceIntent = new Intent(context, BlueDoorStartService.class);
context.startService(serviceIntent);
}
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bluedoor"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<receiver
android:name=".StartBlueDoorAtBootReceiver"
android:enabled="true"
android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name=".BlueDoorStartService" >
</service>
<activity
android:name=".BlueDoor"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
UPDATE Solution(s), 10/22/2015:
Changing the service to:
public class BlueDoorStartService extends Service {
#Override
public IBinder onBind(Intent intent) {
throw new UnsupportedOperationException("Not yet implemented");
}
#Override
public void onCreate() {
super.onCreate();
}
#Override
public void onDestroy() {
super.onDestroy();
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
}
}
and the receiver to:
public class StartBlueDoorAtBootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// Start Service On Boot Start Up
Intent serviceIntent = new Intent(context, BlueDoorStartService.class);
context.startService(serviceIntent);
//Start App On Boot Start Up
Intent App = new Intent(context, BlueDoor.class);
App.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(App);
}
}
resulted in a working configuration using a service w/no misbehaving. However deleting the service all together and modifying the receiver thus:
public class StartBlueDoorAtBootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent App = new Intent(context, BlueDoor.class);
App.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(App);
}
}
also resulted in a functional as well as a more concise configuration that starts the application following boot completion.
Your BroadcastReceiver calls
context.startService(serviceIntent)
so the service will be created if it doesn't exist yet (which will be the case shortly after booting) and thus start the activity from its onCreate() method. So the app works, to a certain extent.
BUT when you call startService(), the system always calls the service's onStartCommand() method. You did not override that method, so the system uses the standard implementation from class android.app.Service.
As you can read on grepcode.com, the method will return a value like START_STICKY by default. This tells the system to keep the service alive until it is explicitly stopped.
In your case, I suppose the system reacted to the swiping by temporarily killing and then reanimating (= creating) the service, which in turn started your activity.
Some information on the service lifecycle can be found here.
What you can do:
Override onStartCommand() to start the activity from there instead of from onCreate(). Then use stopSelf(int) like described here
One last thing: when exiting from the activity, don't use System.exit(0) but call finish() instead, see this SO answer for "why".
Related
I'm stuck with something that seems easy. I want to create a simple app that contains of two buttons: one to start a service and a second one to stop it. I've created my NotifyService class:
public class NotifyService extends Service {
public NotifyService() {
}
private static final String SMS_RECEIVED="android.provider.Telephony.SMS_RECEIVED";
private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
displayNotification(intent);
}
};
private void displayNotification(Intent intent)
{
if(intent.getAction().equals(SMS_RECEIVED)) {
int NOTIFICATION=R.string.local_service_started;
//notification creating
Notification.Builder notificationBuilder = new Notification.Builder(this)
.setContentText("Otrzymano smsa!")
.setContentTitle("SMS!")
.setSmallIcon(android.R.drawable.btn_plus);
Notification note = notificationBuilder.build();
//getting system service
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//displaying notification
notificationManager.notify(NOTIFICATION, note);
}
}
#Override
public void onDestroy() {
super.onDestroy();
unregisterReceiver(broadcastReceiver);
}
#Override
public void onCreate() {
super.onCreate();
registerReceiver(broadcastReceiver,new IntentFilter(SMS_RECEIVED));
}
#Override
public IBinder onBind(Intent intent) {
return null;
}
And here's the code for my MainActivity:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void startServiceBtn(View view)
{
Intent intent = new Intent(this,NotifyService.class);
startService(intent);
}
public void stopServiceBtn(View view)
{
Intent intent = new Intent(this,NotifyService.class);
stopService(intent);
}
And the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pablo.myapplication" >
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".NotifyService"
android:enabled="true"
android:exported="true" >
</service>
</application>
Unfortunately, every time I'm simulating a sending of an sms through Android Device Monitor, it doesn't work, it shows me the default system notification (that by the way is shown even without the permission in manifest- ist that right behavior?)
EDIT:
In Android Device Monitor it still keeps showin Permission Denial: ... requires android.permission.RECEIVE_SMS due to sender.com android.... Yet, I've added this into intent filter, then I don't know why it's happening.
The answer to this question was related to some other matters with permissions that I had last times and it's connected with new permission politics with Marshmallow. More info here.
So the problem can be solver by switching to lower sdk version or calling appriopriate methods (look into above link) in runtime.
I have a onBootCompleted broadcast receiver registered in the manifest.
It runs starts MyService. My service in the onCreate registers 3 more broadcast receivers dynamically.
The 3 new receivers filter on the following intent actions
LOCALE_CHANGED,
TIMEZONE_CHANGED and
CONNECTIVITY_CHANGED.
These works correctly when I run the application from Eclipse but, after I reboot the device and my service starts up none of receivers work.
I have a work around implementation but, I would like to know why this is happening?
Manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:name=".receiver.BootCompletedReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
<service
android:name=".MyService"
android:enabled="true"
android:exported="false"
android:stopWithTask="false" >
</service>
Service:
public class MyService()
{
LocationTimeZoneChangedReceiver mLocationTimeZoneChangedReceiver = new LocationTimeZoneChangedReceiver()
NetworkChangedReceiver mNetworkChangedReceiver = new NetworkChangedReceiver()
public void onCreate()
{
registerReceiver(mLocationTimeZoneChangedReceiver, new IntentFilter(Intent.ACTION_LOCALE_CHANGED));
registerReceiver(mLocationTimeZoneChangedReceiver, new IntentFilter(Intent.ACTION_TIMEZONE_CHANGED));
registerReceiver(mNetworkChangedReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}
}
BootCompletedReceiver:
public class BootCompletedReceiver extends BroadcastReceiver
{
public void onReceive(Context context, Intent intent){}
}
MyApplication:
public class MyApplication extends Application
{
ServiceConnection mServiceConnection = new ServiceConnection() { anonymous class...}
public void onCreate()
{
bindService(new Intent(this, MyService.class), mServiceConnection,Context.BIND_AUTO_CREATE);
}
}
Edited:
Edited code for Plinio.Santos.
It's a big app with many moving parts so at best I can post small code snippets.
Following are the steps I am following for testing:
Push app via Eclipse,
test that network change receiver is working
leave wifi off
Now restart the device
wait for the process to start and turn on wifi.
I believe that the service is not started or bound due errors. Unfortunately I can not say it for sure without all binding/starting code.
Anyway, you can see bellow a code that worked fine after I rebooted (the app started, registered the receiver and is receiving the CONNECTIVITY_CHANGED broadcast.
AndroidManifest.xml:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:name=".TestReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service
android:name=".TestService"
android:exported="true" />
Receiver class:
public class TestReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent != null && Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Toast.makeText(context, "Intent.ACTION_BOOT_COMPLETED receiverd !", Toast.LENGTH_SHORT).show();
context.startService(new Intent(context, TestService.class));
}
}
}
Service class:
public class TestService extends Service {
private BroadcastReceiver mConnectivityChangedReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
if (intent != null && ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
Toast.makeText(context, "ConnectivityManager.CONNECTIVITY_ACTION receiverd !", Toast.LENGTH_SHORT).show();
}
}
};
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onCreate() {
super.onCreate();
registerReceiver(mConnectivityChangedReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}
}
I am new to android, I have created intent's like this -
<receiver android:name=".IncommigCallListener" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
<receiver android:name=".OutgoingCallReciever" >
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
Now i created a service like this -
<service
android:name=".CallLogger"
android:exported="false"/>
Class CallLogger
public class CallLogger extends IntentService {
public CallLogger(String name) {
super(name);
// TODO Auto-generated constructor stub
}
#Override
protected void onHandleIntent(Intent arg0) {
// TODO Auto-generated method stub
System.out.println("service started");
}
}
I don't want to have any activity in my application, i just want to start the service so that it can work in background and receive PHONE_STATE and NEW_OUTGOING_CALL intent.
When i start this application, it doesn't log anything on PHONE_STATE or NEW_OUTGOING_CALL intent.
How can start service in background without using any activity ?
Edit :
public class OutgoingCallReciever extends BroadcastReceiver {
#Override
public void onReceive(Context ctx, Intent intent) {
String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
}
}
and
public class IncommigCallListener extends PhoneStateListener {
#Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
String incommingCallNumber = incomingNumber;
System.out.println("incomming call : " + incomingNumber);
break;
}
}
}
Just start service in your BroadcastReceiver's onReceive method. As you are registering BroadcastReceiver in AndroidManifist, It will always listen for Broadcasts even if application is not running (OS will run it for you).
Example
public class MyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent service = new Intent(context, MyService.class);
context.startService(service);
}
}
EDIT
To start a service on Boot completed you can do something like this.
1) Add permission to your Manifist :
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
2) Register your Broadcast Receiver with BOOT COMPLETE action.
<receiver android:name="com.example.BootBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
3) In BootBroadcastReceiver.java:
public class BootBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent serviceIntent = new Intent(context, MyService.class);
context.startService(serviceIntent );
}
}
You should be able to do something like this in your receiver.
public class OutgoingCallReciever extends BroadcastReceiver {
#Override
public void onReceive(Context ctx, Intent intent) {
String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Intent service = new Intent(context, CallLogger.class);
context.startService(service);
}
}
You need to create an intent and call startService() on it to "launch" the service.
Also for what it's worth you should get out of the habbit of System.out.println use Log.d(tag,msg) to print debugging information to the logcat. You can switch the d to other letters if you want to print in different channels.
Why nothing gets printed is only due to the problem that System.out.println does not work in Android! Where do you think the background process will "print" this thing?
You need to change that to Log.d(tag, msg) and then check your logcat to see the output! Otherwise I guess your code might be running properly.
I want to open my application immediately when S Pen is detached , How can you do this, if the methods put under onSPenDetached is only called when my application is opened again?
Thanks,
Chandu
The following works on my Galaxy Tab A 9.7 with S-Pen (SM-P550) running Android 5.0.2.
Attaching and detaching the stylus creates Broadcast Intents of type com.samsung.pen.INSERT with a booleanExtra named penInsert of false if detached and true if put back into the device.
Thus a Broadcast Receiver can be created that filters this kind of events. The following code is for such a Broadcast Receiver which starts OneNote if the stylus is detached:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class SPenDetachIntentBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent penInsertIntent) {
if (!penInsertIntent.getBooleanExtra("penInsert", true)) {
try {
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage("com.microsoft.office.onenote");
context.startActivity(launchIntent);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
In the Manifest file you need to declare it as a receiver listening for com.samsung.pen.INSERT Broadcast Intents with an intent filter. The following entry in a project's AndroidManifest.xml declares SPenDetachBroadcastReceiver, generates an instance and makes it listening for com.samsung.pen.Insert Broadcast Intents:
<receiver
android:name=".SPenDetachIntentBroadcastReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.samsung.pen.INSERT" />
</intent-filter>
</receiver>
The advantage over using registerSPenDetachmentListener on an SPenEventLibrary object to register a Service with an onSPenDetached method implemented is that you do not need any additional library files and you also do not need additional permissions.
You will need to create a BroadcastReceiver and a Service.
The service:
public class SPenService extends Service {
SPenEventLibrary mSPenEventLibrary = new SPenEventLibrary();
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onCreate() {
super.onCreate();
mSPenEventLibrary.registerSPenDetachmentListener(this, new SPenDetachmentListener() {
#Override
public void onSPenDetached(boolean bDetached) {
if (bDetached) {
Toast.makeText(SPenService.this, "S Pen Detached", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(SPenService.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} else {
Toast.makeText(SPenService.this, "S Pen Inserted", Toast.LENGTH_SHORT).show();
}
}
});
}
#Override
public void onDestroy() {
super.onDestroy();
mSPenEventLibrary.unregisterSPenDetachmentListener(this);
}
}
The receiver:
public class SPenReceiver extends BroadcastReceiver {
#Override
public void onReceive(final Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
context.startService(new Intent(context, SPenService.class));
}
}
}
The manifest (inside the <application> tag):
<receiver android:name=".SPenReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name=".SPenService" >
</service>
Here's the deal, I've been working on making a simple screen locker app that mainly does the following:
removes the keygaurd
disables home and back buttons
runs whenever the screen goes ON after going OFF
runs at boot [not tested yet]
I've DONE MY HOMEWORK and used tons of links (especially on stackoverflow) and still so many problems
number 1 works perfectly :)
number 2 works but not as intended, when I press it, it open the dialog that asks the user for choosing a home application... I don't want that! I want to make a lock screen app, not a home app. (code is provided at the end)
number 3 works before unlocking the screen, but after that, the application doesn't know how to start itself automatically. I've implemented a Broadcast Receiver that is registered in code in the onCreat() method for the lock screen activity. I think this is the problem :S
number 4 this doesn't work at all!
I was testing with a service, but still not working :'(
Code
Manifest I'm sure I'm using the the right permissions, am I?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="himura.test.mylockertest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<receiver
android:name=".EventsReciever"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.SCREEN_OFF"/>
<action android:name="android.intent.action.SCREEN_ON"/>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<service
android:enabled="true"
android:name=".UpdateService"/>
<activity
android:name=".LockPage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
activity the layout is very simple, just one button to unlock :)
public class LockPage extends Activity {
private Button ublockButton;
#Override
public void onAttachedToWindow() {
//this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
super.onAttachedToWindow();
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
///** FIRST THINGS FIRST, START THE SERVICE **/
//startService(new Intent(this, myService.class));
/** REGISTERING RECEIVER **/
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_BOOT_COMPLETED);
BroadcastReceiver mReceiver = new EventsReciever();
registerReceiver(mReceiver, filter);
/** SETTING CONTENT VIEW**/
setContentView(R.layout.lockscreen);
/** REMOVING KEYGUARD RECEIVER **/
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();
/** NORMAL CODE **/
ublockButton = (Button)findViewById(R.id.bUnlock);
ublockButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
}
#Override
public void onBackPressed() {
// Don't allow back to dismiss.
return;
}
//only used in lockdown mode
#Override
protected void onPause() {
super.onPause();
Log.i("event","onPause");
// Don't hang around.
finish();
}
#Override
protected void onStop() {
super.onStop();
Log.i("event","onStop");
// Don't hang around.
finish();
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return false;
}
}
Broadcast Receiver this handles 3 things, screen on/off and boot complete (or it should),,, I've been testing with Logs
public class EventsReciever extends BroadcastReceiver {
//works before unlocking
//after unlocking, keygaurd still off, but receiver has stopped
public static boolean wasScreenOn = true;
#Override
public void onReceive(Context context, Intent recievedIntent) {
Log.i("Check","[BroadCastReciever] onRecieve()");
if (recievedIntent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
wasScreenOn = false;
Log.i("Check","[BroadCastReciever] Screen went OFF");
} else if (recievedIntent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
wasScreenOn = true;
Log.i("Check","[BroadCastReciever] Screen went ON");
Intent intent = new Intent(context, LockPage.class);
context.startActivity(intent);
}
else if(recievedIntent.getAction().equals(Intent.ACTION_BOOT_COMPLETED))
{
Intent intent = new Intent(context, LockPage.class);
context.startActivity(intent);
// Intent intent = new Intent(context, LockPage.class);
// context.startActivity(intent);
// Intent serviceLauncher = new Intent(context, UpdateService.class);
// context.startService(serviceLauncher);
// Log.v("TEST", "Service loaded at start");
}
}
}
Finally, the service doesn't do anything now, I was trying to use it to start the lock screen after it gets unlocked for the first time
public class myService extends Service{
#Override
public void onCreate() {
/** INITIALIZE RECEIVER **/
//RegisterReciever();
}
#Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
// The standard pattern for implementing a Service is to create and run a new thread from onStartCommand
// to perform the processing in the background and stop the Service when it’s complete
//RegisterReciever();
return Service.START_STICKY;
}
/*private void RegisterReciever(){
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_BOOT_COMPLETED);
BroadcastReceiver mReceiver = new EventsReciever();
registerReceiver(mReceiver, filter);
}*/
}
more issues I've found on the internet includes the return of the status bar after turning the screen on (very bad)
in the native keyguard, there is the status bar, but it doesn't function, is there a way to do that?
isn't there a way to just make the locker activity, and tell the system that here u go, use this as the keyguard?
isn't there a way to just make the locker activity, and tell the system that here u go, use this as the keyguard?
If you create your own firmware, presumably there is a way to replace the keyguard with an alternative implementation, considering that most device manufacturers do it. You cannot replace the keyguard via the SDK.
to solve number 2 problem(remove Lock from Home application) remove below line from AndroidManifest.xml file
< category android:name="android.intent.category.HOME" />
Service:
BroadcastReceiver mReceiver=null;
int ReadingBlock = 100;
String PasswordType;
#Override
public void onCreate() {
super.onCreate();
// Register receiver that handles screen on and screen off logic
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
mReceiver = new AutoStart();
registerReceiver(mReceiver, filter);
}
#Override
public void onStart(Intent intent, int startId) {
boolean screenOn = false;
try{
// Get ON/OFF values sent from receiver ( AEScreenOnOffReceiver.java )
screenOn = intent.getBooleanExtra("screen_state", false);
}catch(Exception e){}
if (!screenOn){
} else {
Intent RegularPassword = new Intent(getApplicationContext(), ScreenLock.class);
RegularPassword.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(RegularPassword);
}
}
}
#Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
#Override
public void onDestroy() {
Log.i("ScreenOnOff", "Service distroy");
if(mReceiver!=null)
unregisterReceiver(mReceiver);
}