Is there any way to restart a device per code from within android. I can highly customize all software on the device (tablet). As Backgroundinfo: I want a timer that restarts the device after a defined count if he did not get reseted.
Edit:
If there there is no Buildin-Way is it possible to do this anyway?
In general Google dont allow third party apps to Reboot device below are few link might be helpful
http://groups.google.com/group/android-platform/browse_thread/thread/daf7c685e020d296
http://groups.google.com/group/android-developers/browse_thread/thread/5a97467ef5b4bf47/a1fe9379d4f5e30f?pli=1
This isn't possible from within an app, I believe.
The intent for rebooting the device (ACTION_REBOOT, if I recall, but I'm happy to be corrected!) can only be called from the system itself, not from any software residing on it.
(See the Android reference docs here.)
Related
I would like to detect whether the device (Android and ios) has been previously rebooted before opening the apps. I noticed that there would be many possible ways to achieve it if we could rely on the device clock's time like what has been elaborated here. My concern would be; the device clock can be changed, and the apps can work in offline mode.
Android
My idea would be to store a boolean variable using Android SharedPreferences after device has been rebooted, and set as true. Then check the variable after user opens the apps. If true, then we can confirm that the device is previously rebooted, else not.
ios
I have no idea on how to implement it for ios, but the link above might gives me a hint.
Solution that might works in both platform (not try yet)
If RAM usage cleared after device restart, then I would assume that if RAM usage is on certain level,the device has been rebooted.
Of all the possible ways to achieve the objective, I would prefer to use existing package. But I would happy if you can give your feedbacks for the above ideas.
So my questions would be :
I hate to reinvent the wheel, so any existing Flutter package or any other library which can't be found on https://pub.dev/packages that can be used to detect whether the device has been previously rebooted before opening the apps?
Is there any other possible solution that I missed which already have in Flutter architecture to solve the issue?
Update
I've found a package called boot_completed which only supported on Android.
..and I've found an interesting feature for Android running API level 24
BOOT_COUNT. Horray!
I'm currently working on an app for this kind of device:
link. I want the user to be able to set a timer to shutdown and boot (NOT reboot) at a specific time during the week.
I did a lot of researches but I have't found the answer to my question. Everybody says that's impossible to boot using a timer since the device is supposed to be off. However, in the settings of the device, there is an option "Timer Switch Machine" which allow to do that (as describe in the link above). So I think there is a way to hack this functionality throw my app, if the device is rooted. But I don't know how to do that.
Does anyone have an idea?
This functionality is not part of the AOSP. That means first you have to gain access to the source code (or alternatively talk to someone who has access to it).
You might be able to find the corresponding code by decompiling System apps (especially the app which contains the option).
Otherwise you'd have to find a contact to the developer (probably via the manufacturer).
If you have the sources, the easiest way to hook into it is normally using xposed.
But depending on the actual implementation (e.g. if it's a shell call) there might be a better way.
I have implemented a Broadcast Receiver to open my app from the launcher. The number to open is #1234#
Now it works perfectly in some devices while it doesn't in some. Now my question is how is this even possible?
If it works, then it should work in all devices isn't it? Also I need suggestions on what would be the best practice to ensure that it works on all devices.
Thanks.
Now my question is how is this even possible?
Yes it is pretty much possible.
If it works, then it should work in all devices isn't it?
No, Reason behind your implementation not working can be but not limited to are given below.
1) Every Phone Manufacturer tweak Android OS code(As Android is Open Source). There can be chance of have given priority to System Apps first then public
apps.
2) There can be other apps(System/Public both) running on the phone, which are listening on the same BroadCast Intent and taking action before your app does anything.
3) Phone are slow and your receiver getting command little later then expected!!
Share more details on your testing to get more feedback.
I'm trying to develop an app that would normally be considered to be malware, but the customer's demands are very specific and logical. We have around 50-100 cheapset Android phones that are bolted down, plugged in, and the app is supposed to send some of the sensor data via tcp to a remote server. It sounds simple enough, but there are two features that I struggle with (since I'm not an experienced Android developer, and have never rooted a phone):
#1 The app should be always on. If it crashes, server should get the error report (stack trace), and the app should be restarted after 10 minutes one more time before giving up. Also, the OS could theoretically kill the app (although I did my best to minimize the memory usage). I'd like to somehow handle that as well.
#2 It would be great if the app could be remotely updated, or auto-updated, with no user interaction whatsoever (since there is no conventional user).
To implement #1, I see no other solution than to root the phone (AlarmsManager doesn't seem to work as I expected, and adding another application to take care of the first one just feels wrong). Is there anything I'm missing?
I don't know how to approach implementing feature #2 at all. If I put the app on the market and check the "keep this application always up to date" checkbox while installing it, will that work? I fear that the auto-update would not occur while the service is running, and even if it did, that the OS would not restart the service after installing the update (unless feature #1 is implemented). If I programatically download the latest .apk and open it, I still need the user to click the "Install" button. I'm even considering implementing the updateable part in some scripting language.
Is there a solution to these problems within the limits of Android API?
EDIT: Thank you all for your answers, you've been very helpful. It seems that the only way to make Android behave as a non-user piece of hardware is to root it. That's the only way to do silent auto-updates. Always on can then be implemented by enabling cron (AlarmManager apparently doesn't fire the event in case of service termination via crash, but it could be used by another trivial, non-crashable service to keep the first one running).
For #1 you can use an foreground service. I don't know how often you need to get sensor data, but what's the problem with AlarmManager? I don't see how rooting could help with #1 though. You can't really do #2 without rooting or building your firmware. If you install your app as a system app (in /system/app) you can use a hidden PackageManager to silently install the new version. Using Market/Play autoupdate should work as well, but you have no way to control the update schedule. And, yes, it won't restart your service, but if you use AlaramManager, this shouldn't be a issue.
All in all, stock Android is not exactly an embedded system that gives you full control, so depending on how much time/effort you are willing to spend, you might want to customize it somewhat (or find a custom ROM that gets close to your requirements).
Re: question #2, there are a few open-source (licensed under the Apache Software License 2.0) options you may check and see how it works.
https://github.com/lazydroid/auto-update-apk-client is the android client for the auto update service (i'm affiliated with), which is small, easy to implement and supports silent updates on rooted devices.
https://github.com/commonsguy/cwac-updater is written by Mark Murphy, however it might require you to run your own update server and I'm not sure about silent updates.
There is some way to know if my Android app is running on debugger or on a phone?.
I want to check some variable, property, or something like that to know where the app is running to prevent some crash when I call some 3rd applications (not available on debugging time)
Thanks and sorry for my poor english
You might want to look into DDMS
You can access logs, threads and heap information. also check running apps and services. You can also simulate phone behaviours on the emulator, like an incoming call, as an example. Well, I would also recommend reading all the information in the debugging section, there are a lot of useful tools available for Android developers.
You mean detecting the emulator? Because you can run under debugger also on your device.
Use this to detect the emulator (worked for me a while ago):
"google_sdk".equals(Build.MODEL)