Samsung devices does not close app drawer after CLOSE_SYSTEM_DIALOGS broadcast - android

I'm developing a simple Kiosk Mode application for Android 6.0. I have everything working on devices from Xiaomi, HTC, Lenovo, etc. but I can't get one feature working on any Samsung device.
The feature is automatic closing of every system system dialog using
Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
sendBroadcast(closeDialog);
This is broadcasted from a Service.
On my other, non-samsung devices, everything works and all system dialogs closes, but on any Samsung device (S5, S6 edge, ...) this broadcast gets ignored and for example the app drawer stays opened.
I've observed that even using ADB to broadcast this intent, app drawer stays opened, but for example the shutdown device dialog gets closed if I broadcast this from adb.
Please note that this is not malicious action in context of this software, this is for client, that requires this feature and it is completely solicited.
I've done research on Samsung Knox, but we would have to obtain their license for using the Knox Standard SDK and that is not something that is in the scope of this project.
So my question is: Do you have any idea how to make this work (closing the app drawer with ACTION_CLOSE_SYSTEM_DIALOGS intent) on samsung devices with Knox installed?
Thanks.

Try doing it like this :
#Override
public void onWindowFocusChanged(boolean focus) {
super.onWindowFocusChanged(focus);
if (! focus) {
Intent close= new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
sendBroadcast(close);
}
}

The problem with the most commonly found solution is that dialogs are totally different window, so you need to override the onWindowsFocusChanged on them as well. That can lead to a lot of work, plus the menu also open the same flaw to call the power menu.
The best solution I found is to implement a service to close the system dialogs when a long press of the power key is detected. I tested on couple of LG devices (Android 5.1.1 and 6.0) and calling this from a service was working just fine:
sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
But on Samsung tablets (Android 5.1.1) it did not work, after trying few different solutions with no luck. I finally got it working when send an intent to an activity and make the activity send the broadcast:
Add this to your manifest:
<service
android:name="com.mypackage.services.PowerButtonService"
android:enabled="true"
android:exported="true"
android:permission="android.permission.SYSTEM_ALERT_WINDOW"
android:stopWithTask="true"/>
<activity
android:name="com.mypackage.activities.CloseSystemDialogActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="CloseSystemDialogActivity.ACTION_CLOSE_DIALOGS"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
The service:
public class PowerButtonService extends Service {
private View view;
private WindowManager windowManager;
#Override
public void onCreate() {
super.onCreate();
LinearLayout linearLayout = new LinearLayout(getApplicationContext()) {
#SuppressWarnings("unused")
public void onCloseSystemDialogs(String reason) {
if ("globalactions".equals(reason)) {
final Intent intent = new Intent(CloseSystemDialogActivity.ACTION_CLOSE_DIALOGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
};
linearLayout.setFocusable(true);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(100, 100, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
params.gravity = Gravity.START | Gravity.CENTER_VERTICAL;
view = LayoutInflater.from(this).inflate(R.layout.empty, linearLayout);
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
windowManager.addView(view, params);
}
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onDestroy() {
super.onDestroy();
// VERY IMPORTANT
windowManager.removeView(view);
}
#Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
return START_STICKY;
}
}
Dummy activity:
public class CloseSystemDialogActivity extends Activity {
public static final String ACTION_CLOSE_DIALOGS = "CloseSystemDialogActivity.ACTION_CLOSE_DIALOGS";
#Override
protected void onCreate(#Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
finish();
}
}
Notice that you NEED to START and STOP the service otherwise when your application is not running (out of kiosk mode) you might not be able to call the power menu if you need to.

Related

Service not running in Background when app terminated on Oreo

I have developed small app to detect changes in network like on, off or connection change Wifi to Ethernet, whenever app closed or running in all cases.
Provided code working for me upto Nuget 7, when testing app in Oreo 8 background services not working when app terminated.
How can I get it work in Oreo?
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
Intent vpnServiceIntent = new Intent(getBaseContext(), MyService.class);
startForegroundService(vpnServiceIntent);}}
WifiReceiver.java file
public class WifiReceiver extends BroadcastReceiver {
static final String CONNECTIVITY_CHANGE_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (CONNECTIVITY_CHANGE_ACTION.equals(action)) {
if (!isConnected()) {
if (context != null) {
Toast.makeText(context," Not connected...",Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(context,"connected...",Toast.LENGTH_LONG).show();
}
}
}
}
MySevice.java file
public class MyService extends Service
{
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
IntentFilter filter = new IntentFilter();
filter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
WifiReceiver receiver =new WifiReceiver();
registerReceiver(receiver,filter);
return START_STICKY;
}
}
Manifest.xml file
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
<receiver android:name=".WifiReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
<service android:name=".MyService" />
</application>
Note: If I call startForeground(101, notification); in onCreate of MyService class, my above code is working but showing permanent notification icon on top most status bar, that I don't want at all.
since Android 8.0 (API level 26) it is basically impossible to run background service while app is not visible because of Battery optimizations and security reasons.
It sucks, many useful apps can not run and work normally.
They recommend to use ForegroundService which requires to show notification.
It would be almost okay, but these ForegroundServices also gets killed after some time.
To avoid killing them you need to make BatteryOptimization prompt so user would let service running in background without killing.
But it is not over yet... Services is still being killed on most of Manufactures like Samsung, Huawei and so on because they has they own badly implemented BatteryOptimizations running parallel with native one... and if user want some app avoid to be killed while running in background it has to go long way to settings find provider specific settings and let app run....
here is an example how to change these provider specific settings on Slack
I think it is worst thing that happened to Android.....

How to make sure new NFC intent delivers to my activity after screen off/on again?

I have a react-native app which reads NFC tags and writes a URL to them.
It uses ForegroundDispatch to make sure the app captures the scanned info and doesn't navigate away to the browser when the link is detected. The link is used only when the app is not launched, it opens a browser and shows information from my server to the external user.
When I'm in the app and I turn the screen off (power button), then turn it back on again and scan an NFC tag, the browser opens up. It looks like the scanned intent doesn't deliver to the app and is instead handled by the phone as default. After the first scan, which opens the browser, I navigate back to the app and the following scans work fine inside the app.
Here is the twist: on most phones it works as expected. Works on Pixel 3 (Android 9), on Huawei (Android 5.1) on Sony (Android 7) an a few others. But when I use UleFone X2 (http://ulefone.com/product.html) this issue occurs.
Am I doing something incorrectly to initialize the app so it handles itself the same every time, even when it's resumed?
From my research it looks like UleFone disables NFC when the screen goes off and when it turns back on, am I not initializing it properly? If I open the recent apps and navigate away from my app, then back into it, the NFC starts working.
This is my main activity:
public class MainActivity extends ReactActivity {
private NfcAdapter mAdapter;
private PendingIntent mPendingIntent;
private IntentFilter[] mFilters;
private String[][] mTechLists;
private int mCount = 0;
#Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
}
#Override
protected void onCreate(Bundle savedState) {
super.onCreate(savedState);
mAdapter = NfcAdapter.getDefaultAdapter(this);
mPendingIntent = PendingIntent.getActivity(this, 0,
new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
try {
ndef.addDataType("*/*");
} catch (MalformedMimeTypeException e) {
throw new RuntimeException("fail", e);
};
mFilters = new IntentFilter[] {
ndef,
};
mTechLists = new String[][] { new String[] {NfcA.class.getName()}, new String[] {MifareClassic.class.getName()}, new String[] {Ndef.class.getName()}, };
Log.d("scantest", "onCreate completed");
}
#Override
protected void onPause() {
super.onPause();
if (mAdapter != null) mAdapter.disableForegroundDispatch(this);
Log.d("scantest","onPause completed");
}
#Override
public void onResume() {
super.onResume();
Intent intent = getIntent();
if (mAdapter != null) mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists);
Log.d("scantest","onResume completed");
}
Expected behaviour:
All Android phones that support NFC handle NFC scanning in the app the same way, on launch and after it is resumed. The intent should always deliver to my app.
Current behaviour:
Most phones work fine after screen goes off/on again. On some phones (UleFone) if I turn the screen off/on, the first scan opens the browser, and the following ones work inside the app.
Current workaround:
After turning screen off/on, if I navigate away from the app using recent apps (I don't even have to click on another app, just have to make sure the recent apps tiles come up) then click to go back to my app, NFC doesn't fail on the first scan.
Otherwise the first scan fails and opens the browser.
A workaround could be to add this intent-filter to your activity
https://developer.android.com/guide/topics/connectivity/nfc/nfc#tag-disc
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
</intent-filter>
With this you declare to android your app is want to catch any NFC tag. If device has another app which catch nfc tag, then a menu is shown to user to select which app get NFC intent.

Can't get voice commands on Android Auto Media App work

I have an Android App with working Auto capabilities which has been rejected from the store because:
"Your app does not support all of the required voice commands.
For example, your app does not contain an Intent filter for action "android.media.action.MEDIA_PLAY_FROM_SEARCH"."
So i looked to at least make the app respond to "play music on X app" but by looking at the documentation I can't get it to work. I added this to my main activity (which is not the launcher activity, it controls the service via binder)
<intent-filter>
<action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
which triggers a MediaBrowserServiceCompatwhich is initialized this way:
manifest:
<service
android:name=".Services.RadioService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>
part of the code:
#Override
public void onCreate() {
super.onCreate();
audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
mSession = new MediaSessionCompat(this, "RService");
mSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS
| MediaSessionCompat.FLAG_HANDLES_QUEUE_COMMANDS);
mSession.setCallback(mCallback);
mSessionConnector = new MediaSessionConnector(mSession);
setSessionToken(mSession.getSessionToken());
setMediaBrowser();
initializeReceiver();
C_F_App.createNotificationChannelPlayer(getApplicationContext());
rNController = new RadioNotificationController(this, mSession, getApplicationContext());
}
final MediaSessionCompat.Callback mCallback =
new MediaSessionCompat.Callback() {
#Override
public void onPlayFromMediaId(String mediaId, Bundle extras) {
playForAuto(mediaId);
}
#Override
public void onPlayFromSearch(String query, Bundle extras) {
super.onPlayFromSearch(query, extras);
Log.d("Test", "Test");
}
#Override
public void onStop() {
playPause();
}
#Override
public void onPlay() {
playPause();
}
#Override
public void onPause() {
playPause();
}
};
public void setMediaBrowser() {
mediaBrowser = new MediaBrowserCompat(getApplicationContext(),
new ComponentName(getApplicationContext(), this.getClass()),
new MediaBrowserCompat.ConnectionCallback() {
#Override
public void onConnected() {
super.onConnected();
}
#Override
public void onConnectionSuspended() {
super.onConnectionSuspended();
}
#Override
public void onConnectionFailed() {
super.onConnectionFailed();
}
}, null);
mediaBrowser.connect();
}
#Override
public long getSupportedPrepareActions() {
return PlaybackStateCompat.ACTION_PREPARE_FROM_MEDIA_ID |
PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID |
PlaybackStateCompat.ACTION_PREPARE_FROM_SEARCH |
PlaybackStateCompat.ACTION_PLAY_FROM_SEARCH;
}
Auto capabilities work fine.
When i try to call this app on Auto from the emulator to play music it just does't do anything, it does not say errors or other stuff, it just closes google speak and then returns to the normal display. The method onPlayFromSearch is never called and it should be the one Auto would call if a voice command is sent.
Can someone help me figure out what i'm doing wrong? Google doc is pretty useless this way, Google UAP doesen't look to have this capability like the old version but looking at the old UAP version i cannot figure out what I'm doing wrong.
PS. The app is not published yet with this functionality
Thanks in advance.
To clear the review process, you’ll only need to get “Play X” (while the app is running in the foreground) working. After adding the intent filter, and if the app handles the search query while its running, I’d kick off another app review.
Otherwise, I believe it’s more of a Google Assistant feature that handles “Play X on Y” when the app is not in the foreground. I don’t have all the details on this, but the assistant may be querying their servers for the app name and package. If it isn’t published yet, it may not work locally.
EDIT
The best way to test your intent filter to clear the app review is to call the intent from adb on the mobile device with:
adb shell am start -a android.media.action.MEDIA_PLAY_FROM_SEARCH
If your app appears in the following media list drawer, the intent filter is setup correctly. You should then see the onPlayFromSearch "Test" log fire when "Play music" is sent while the app is running on Android Auto via the Desktop Head Unit.

Android pin activity on boot

I've got an app that registers itself as the default launcher and pins itself automatically when started.
This all works fine when installing the app. It pins itself and only the back button is visible.
The problem is that when the device first boots up, it does not pin properly. I see a series of toasts "Screen pinned" and "Screen unpinned" multiple times. The "Home" and "Recent Tasks" buttons are still visible as well.
--
Running "adb shell dumpsys activity activities" - the last lines indicate that it is not pinned:
mLockTaskModeState=NONE mLockTaskPackages (userId:packages)=
0:[com.example.myapp]
mLockTaskModeTasks[]
--
Testing device Asus ZenPad running Marshmallow/6.0/23
I'm relying on the MainActivity manifest attribute "lockTaskMode" to pin (rather than activity.startLockTask()):
<activity
android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="#string/launcher_main"
android:launchMode="singleTask"
android:lockTaskMode="if_whitelisted"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Any help or pointers would be appreciated
I had the same problem and I could really only find one solution. I'm not sure why but yeah, something in android prevents task locking when booting up which boggles my mind since the task lock was designed to create these "kiosk" type of applications. The only solution I could find was to detect for a case when it didn't lock then restart the application. Its a little "hacky" but what else can you do?
To detect for the case where it didn't lock I created a state variable and assigning states (Locking, Locked, Unlocking, Unlocked). Then in the device admin receiver in onTaskModeExiting if the state isn't "Unlocking" then I know it unlocked on its own. So if this case happened where it failed, I then restart the application using this method (which schedules the application in the alarm manager then kills the application):
how to programmatically "restart" android app?
Here is some sample code:
DeviceAdminReceiver
#Override
public void onLockTaskModeEntering(Context context, Intent intent, String pkg) {
super.onLockTaskModeEntering(context, intent, pkg);
Lockdown.LockState = Lockdown.LOCK_STATE_LOCKED;
}
#Override
public void onLockTaskModeExiting(Context context, Intent intent) {
super.onLockTaskModeExiting(context, intent);
if (Lockdown.LockState != Lockdown.LOCK_STATE_UNLOCKING) {
MainActivity.restartActivity(context);
}
Lockdown.LockState = Lockdown.LOCK_STATE_UNLOCKED;
}
MainActivity
public static void restartActivity(Context context) {
if (context != null) {
PackageManager pm = context.getPackageManager();
if (pm != null) {
Intent intent = pm.getLaunchIntentForPackage(context.getPackageName());
if (intent != null) {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
int pendingIntentId = 223344;
PendingIntent pendingIntent = PendingIntent.getActivity(context, pendingIntentId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, pendingIntent);
System.exit(0);
}
}
}
}
private void lock() {
Lockdown.LockState = Lockdown.LOCK_STATE_LOCKING;
startLockTask();
}
private void unlock() {
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
if (am.getLockTaskModeState() == ActivityManager.LOCK_TASK_MODE_LOCKED) {
Lockdown.LockState = Lockdown.LOCK_STATE_UNLOCKING;
stopLockTask();
}
}
In truth this is a simplified version of what I implemented. But it should hopefully get you pointed towards a solution.
The only solution I found as for now : make another launcher app, without locktask, which will trigger main app every time when launcher appears. This prevent user for waiting few more seconds before LockTasked app is being called with on BOOT_COMPLETED receiver. So we can meet this problem only when lockTask app has launcher properties for some activity in manifest.
Sorry for late answering, but...
Anyone has this problem can do this tricky work in first (LAUNCHER/HOME) activity (e.g. MainActivity):
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (mSharedPreferences.getBoolean(KEY_PREF_RECREATED, false)) {
mSharedPreferences.edit().putBoolean(KEY_PREF_RECREATED, false).apply();
// start LOCK TASK here
} else {
mSharedPreferences.edit().putBoolean(KEY_PREF_RECREATED, true).apply();
finish(); // close the app
startActivity(new Intent(this, MainActivity.class)); // reopen the app
return;
}
setContentView(R.layout.activity_main);
// other codes
}

Problems with android lock in custom lock screen app

I built a custom lock screen app that uses a broadcast receiver and service to listen for when the user turns on or off the screen and from there launch my activity. The activity is supposed to completely replace the lock screen. In order to do this my app is supposed to disable the android stock lock so that my app can function as the new lock screen.
Instead what happens is once the application is first installed the the service first started the application appears to be working. and when the user first turns off the screen of their phone when they turn it back on they are presented with my app running on top and is able to unlock their phone with my app. But then once inside the android OS if the user presses the home button the next time they turn off the screen and turn it back on instead of being brought back to my application they are brought to the stock unlock screen with my application open underneath it, when it should be on top.
Here is my code:
My Service:
public class MyService extends Service {
#Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
#Override
public void onCreate() {
super.onCreate();
Log.d("MyService","Service STARTED");
final IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
final BroadcastReceiver mReceiver = new ScreenReceiver();
registerReceiver(mReceiver, filter);
}
}
My broadcast receiver:
public class ScreenReceiver extends BroadcastReceiver {
public static ArrayList<String> runningApplications = new ArrayList<String>();
private Context ctext;
public static boolean screenIsLocked;
public static KeyguardManager keyguardManager;
public static KeyguardLock lock;
#Override
public void onReceive(final Context context, final Intent intent) {
ctext = context;
keyguardManager = (KeyguardManager)ctext.getSystemService(Activity.KEYGUARD_SERVICE);
lock = keyguardManager.newKeyguardLock(Context.KEYGUARD_SERVICE);
lock.disableKeyguard();
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
screenIsLocked = true;
Log.d("ScreenReceiver", "False");
Intent intenti = new Intent();
intenti.setClass(context, starterActivity.class);
intenti.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intenti.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intenti);
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
screenIsLocked = false;
Log.d("ScreenReceiver", "True");
Intent intenti = new Intent();
intenti.setClass(context, starterActivity.class);
intenti.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intenti.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intenti);
}
}
My activity that is started is basically empty with just one unlock button that calls finish(); when pressed.
The behavior of keyguard-related logic can vary from device to device. That's because lockscreens are often custom-made by device manufacturers (i.e. not stock), some of them respect the keyguard logic you use, some don't.
Also, afaik the newer way to control keyguard is to use window flags:
// inside activity
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
This will not solve the problem though, devices still have their say about this.
E.g. from my experience, Galaxy Nexus will show your activity's window above keyguard but will not dismiss it (you'd think Google-branded device should respect the flag, eh), so if you hit the back button in your activity - you'll get standard lockscreen --- while HTC One X seems to handle the dismiss part properly: your activity window will cause standard lockscreen to get dismissed as expected.
I found no way to force all devices to behave properly. Android API is not meant to enable you to create custom lock screens (at least not currently). Take a look at the ones in the store - they all have the exact same problem of not being stable enough.
As Dianne Hackborn says in this Google Groups answer, anything you can do in this regard is a hack so expect it to break from time to time.
I tried to compile your code and got the same error you were talking about. I tried to modify it to make it to work and finally got the problem!!!
public class ScreenReceiver extends BroadcastReceiver {
public static ArrayList<String> runningApplications = new ArrayList<String>();
private Context ctext;
public static boolean screenIsLocked;
public static KeyguardManager keyguardManager;
public static KeyguardLock lock;
#Override
public void onReceive(final Context context, final Intent intent) {
ctext = context;
keyguardManager = (KeyguardManager)ctext.getSystemService(Activity.KEYGUARD_SERVICE);
lock = keyguardManager.newKeyguardLock(Context.KEYGUARD_SERVICE);
lock.disableKeyguard();
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
screenIsLocked = true;
Log.d("ScreenReceiver", "False");
Intent intenti = new Intent();
intenti.setClass(context, starterActivity.class);
intenti.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intenti.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intenti);
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
screenIsLocked = false;
Log.d("ScreenReceiver", "True");
Intent intenti = new Intent();
intenti.setClass(context, starterActivity.class);
intenti.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intenti.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intenti);
}
}
With this change to the broadcast receiver class I was able to overcome the problem
Try it and tell me if there is any problem.
EDIT:I think the problem might lie in the finish() method....Android dumps apps when it requires memory...I think finish() might be helping android in trashing the app(and this might be the reason why your problem occurs randomly)

Categories

Resources