Start an activity even if we lock the device - android

I'm developing an alarm aplication, so when the alarm goes on it start an activity with an off button
It's very simple, but my question, is there a way to start the activity even if the device is locked???

You need to use the WakeLock and also disable your keyboard for the respective Activity. They can be achieved by help of WindowManager.LayoutParams class.
WakeLock allows your app to wake up the screen i.e. turn the display on while your Activity or your complete app is running in the foreground. To learn more about implementing the WakeLock go through the following link:
http://developer.android.com/training/scheduling/wakelock.html
To disable your keyguard you need to use WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED and/or WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD flags for the respective Activity.
To know more about them, go to the following links:
http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_DISMISS_KEYGUARD
http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_SHOW_WHEN_LOCKED
You will also need to use the following permissions in the Manifest file of your Android Project:
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />

You need the following permission in AndroidManifest.xml file:
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
Check this link

Related

Approval for background location on Android?

I developed an Android App with Qt. Some time ago I got an E-Mail "Approval for background location" from Play Store. I'm not familiar with Java and I don't understand the problem.
My App uses GPS only if the app is visible (in foreground), but not if it is invisible (background).
My Manifest.xml looks like this:
<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="28"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.android.vending.BILLING"/>
Now I found on Play Store
...the ACCESS_BACKGROUND_LOCATION permission only affects an app's access to location when it runs in the background.
For me this means because I don't use ACCESS_BACKGROUND_LOCATION my App only uses GPS if it is visible (foreground). So what is the problem? Thanks...
I had a very similar problem. I double checked my AndroidManifest.xml, there was no ACCESS_BACKGROUND_LOCATION in it.
I use the QGeoPositionInfoSource from C++ to get periodic location updates. I never called the stopUpdates() function, that had to be fixed. It must be called when the app goes to background, e.g.: onPause.
Here is a very useful video with the clue, and some other useful reading material:
https://youtu.be/xTVeFJZQ28c?t=394
https://developer.android.com/training/location/permissions
https://youtu.be/xTVeFJZQ28c?t=394
https://developer.android.com/about/versions/oreo/background-location-limits
There is a signal QGuiApplication::applicationStateChanged which can be utilized for this, an example code:
if (const auto *const gui =
qobject_cast<const QGuiApplication *const>(qApp)) {
connect(gui, &QGuiApplication::applicationStateChanged, this,
[&](Qt::ApplicationState state) {
switch (state) {
case Qt::ApplicationState::ApplicationActive:
source->startUpdates();
break;
default:
source->stopUpdates();
}
});
}
The source is a pointer for the QGeoPositionInfoSource.

Wake up device programmatically

I want to wake up and unlock a device. Then, I'd like show an activity when the user has new message from Firebase.
I wrote this on onResume() method:
window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
This works for devices with API > 19. The problem is that in KitKat, it either does nothing or it wakes up the screen but doesn't unlock the device.
Also I set the right permissions in the AndroidManifest.xml:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
Also in MyFirebaseMessagingService.class, I'm starting an activity with FLAG_ACTIVITY_NEW_TASK as flag.
Does anyone know what am I missing?
Thanks for the help.
Ok i found it. I just add that piece of code and it worked
KeyguardManager manager = (KeyguardManager) this.getSystemService(Context.KEYGUARD_SERVICE);
KeyguardManager.KeyguardLock lock = manager.newKeyguardLock("abc");
lock.disableKeyguard();

Turn off Restrict background data programmatically

I have a HTC one M8 running Android 5. I have gone into settings -> more -> data usage -> restrict background data (checked)
This should turn background data off.
I would like to turn it back on (uncheck the checkbox) programmatically with the following code in onCreate of one of my Activities.
ContentResolver.setMasterSyncAutomatically(true);
.
Unfortunately it doesn't turn back on. I have the following in the manifest
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
Are there any ideas why this isn't working?
thanks in advance

Adding Permissions in AndroidManifest.xml in Android Studio?

In Eclipse we were able to add permissions in AndroidManifest.xml by going to AndroidManifest.xml->Permission-> Adding permissions.
How to add permissions in Android Studio? How can we get a list of all the permissions that we can add to an Activity ?
You can only type them manually, but the content assist helps you there, so it is pretty easy.
Add this line
<uses-permission android:name="android.permission."/>
and hit ctrl + space after the dot (or cmd + space on Mac). If you need an explanation for the permission, you can hit ctrl + q.
You can type them manually but the editor will assist you.
http://developer.android.com/reference/android/Manifest.permission.html
You can see the snap sot below.
As soon as you type "a" inside the quotes you get a list of permissions and also hint to move caret up and down to select the same.
Go to Android Manifest.xml
and be sure to add the <uses-permission tag > inside the manifest tag but Outside of all other tags..
<manifest xlmns:android...>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
This is an example of the permission of using Internet.
You can add manually in the manifest file within manifest tag by:
<uses-permission android:name="android.permission.CAMERA"/>
This permission is required to be able to access the camera device.
It's quite simple.
All you need to do is:
Right click above application tag and click on Generate
Click on XML tag
Click on user-permission
Enter the name of your permission.
Put these two line in your AndroidMainfest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

when does a Leadbolt notification ad show?

I have implemented the notification ads per the "How-to" guide:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
and
String leadboltNoticationId = Application.getInstance().getLeadboltNoticationId();
AdController myController = new AdController(getApplicationContext(),
leadboltNoticationId);
myController.setAsynchTask(true);
myController.loadNotification();
no ads show in the notification bar. Nothing shows in the logs. "leadboltNoticationId" is filled correctly with the id. How long do i need to wait for an ad to show up? Is there a way to force an ad to show up immediately? I don't have access to the docs so please dont reference them unless you are going to give me a publicly accessible download link.
You can force to show the notification by setting the notification in your Leadbot-Accout to recurring.

Categories

Resources