Here is my code for starting a service.
public class MyStartupIntentReceiver extends BroadcastReceiver
{
public void onReceive(Context context, Intent intent)
{
Intent callService = new Intent();
callService.setAction("com.xxxx.yyyy.services.StartServiceActivity");
context.startService(callService);
}
}
In manifest file i'm defining broadcast receiver like following.
<receiver android:name=".MyStartupIntentReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"
/>
</intent-filter>
</receiver>
Im declaring the service like following in manifest file
<service android:name=".services.CallService">
<intent-filter>
<action
android:name="com.xxxx.yyyy.services.StartServiceActivity" />
</intent-filter>
</service>
Once user launched my application im starting service from my activity
serviceIntent = new Intent(SplashScreen.this, StartServiceActivity.class);
getApplicationContext().startService(serviceIntent);
Issue is service is working fine with android2.3.5 SDK devices. but not with 4.0 devices. Anything wrong with my code. Please help me to solve.
I find a article from the Internet, hope that it can help u:
Broadcast Regression Confirmed
In a previous post, I cited evidence that the BOOT_COMPLETED broadcast will not work out of the box on Android 3.1 until the user uses your app.
It’s actually somewhat bigger than that.
In the issue that I filed seeking clarification, Ms. Hackborn indicated:
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.
As a result, when applications are first installed, they are totally ignored by the system until and unless the user manually launches something: clicking on a launcher activity or adding an app widget, most likely.
Developers who had been relying upon getting some sort of system broadcast without user intervention will need to adjust their apps for Android 3.1.
As I wrote in the previous post:
I expect that most apps will be OK. For example, if your boot receiver is there to establish an AlarmManager schedule, you also needed to establish that schedule when the app is first run, so the user does not have to reboot their phone just to set up your alarms. That pattern doesnot change – it’s just that if the user happens to reboot the phone, it will not set up your alarms, until the user runs one of your activities.
UPDATE: To clarify the above quote, once the user runs the app for the first time (and does not Force Stop it), everything behaves as before — a reboot will cause BOOT_COMPLETED broadcasts to be received and so on. However, if the user installs the app, until and unless they run the app manually, no broadcasts will be received. And if the user force-stops the app, until and unless they run the app manually, no broadcasts will be received.
This change is not terribly shocking, as it ratchets up the security another notch by limiting ways malware can run without user knowledge. While it does not offer perfect security — the malware can still install its own copy of an Angry Birds launcher icon and hope users screw up — it is an improvement.
Related
I got following error on google play store but I have no idea why this error occured. They said that it is happing on (Sharp AQUOS sense2 SH-01L Android 9 (SDK 28) ).
I have logcat but I can't find anything in logcat too. I already released to production. This one is my bugs fixed for new release.
ANR in com.google.android.apps.tachyon;PID: 18069;Broadcast of Intent {
act=android.accounts.LOGIN_ACCOUNTS_CHANGED flg=0x5000010 cmp=com.google.android.apps.tachyon/com.google.apps.tiktok.account.data.device.DeviceAccountsChangedReceiver_Receiver };
A similar Error occurred for me as well.
"ANR in com.google.android.apps.tachyon" at same device "Sharp AQUOS sense2 SH-01L"
E/ActivityManager(1566): ANR in com.google.android.apps.tachyon
E/ActivityManager(1566): PID: 18457
E/ActivityManager(1566): Reason: Broadcast of Intent { act=android.intent.action.LOCALE_CHANGED flg=0x11200010 cmp=com.google.android.apps.tachyon/.common.applifecycle.LocaleChangeReceiver }
I believe this device has com.google.android.apps.tachyon app is installed by default and an automatic update for this app could be running in the background (just a guess) which crashes anytime.
The crash is just a coincidence.
It will not happen every time with the same app and with the same use case. It will also not happen with any other device. just update the versionCode and publish the App again.
One other option is to go to the device catalog and mark this device as not supported.
After a lot of research, I think I have finally solved this for my app.
In my case, other than my main activity, the other Activies were only called by my app. In my activities in my AndroidManifest.xml, I had
android:exported="true"
Of course, this allows these activities to be invoked by other external activities/etc
By changing this to:
android:exported="false"
...it prevents the activity from being called.
In my case and going through the logs, I didn't see anything that jumped out and bit me but my research led me to believe that com.google.apps.tiktok.* was some sort of old transactional piece of Android. Also, I noticed my Tutorial activity was logging well after it should have been.
My suspicion is the test may actually be real and intended to check for either Activities handling external launches or checking for a security injection of some kind.
I think the use case is likely that an Android user is changed on the phone (usually at end of these robo tests), ticktok handles that and sends this intent/message to all externally known Activities. If so, that would mean either the Activities have to not be exported or handle the intent appropriately.
Anyhow, this change helped me tremendously and I haven't hit this with this app since after about 100 robo tests. Hope it helps someone else.
I think this is a problem with Google Play Store testing devices. Problems went away without me making any changes on a new release.
I am testing OpenIAB to upgrade from amazon IAP v1 to v2 in Unity. I am using the latest OpenIAB unity plugin.
I am able to query and purchase an IAP but then the call to OpenIAB.consumePurchase returns a failure callback. I am testing with App Tester on amazon.
I get the error below "original json invalid" after calling OpenIAB.consumeProduct(..)
Original json is invalid:
{"itemType":"inapp","orderId":"","packageName":"","sku":"productexample","purchaseTime":0,"purchaseState":0,"developerPayload":"","token":"q1YqVrJSSi_OKynKLEhNzC4uyc9OzSvOTS3Ozc8vKMnMzzNU0lFKAaoxNDEzMzY3NzM2NjY1AoqVAsVyjD18zCMKClx9M4r83V3ySossdUtzygrzc4uC080KK_1dvHMTM8zNcrxCbYFaSpSsDGoB","originalJson":"","signature":"","appstoreName":"com.amazon.apps","receipt":”"}
I am having multiple other issues like I don't get back orderId or receiptID from queryInventorySuccess callback for the purchase that is already made. I see the valid productId but no orderId even though I see the receiptId on App Tester. What is the difference between Token, ReceiptId and OrderId?
Also what is the difference in using the below in manifest for android:name in receiver. Could there be a problem here?
<receiver android:name="com.amazon.inapp.purchasing.ResponseReceiver">
<intent-filter>
<action
android:name="com.amazon.inapp.purchasing.NOTIFY"
android:permission="com.amazon.inapp.purchasing.Permission.NOTIFY"/>
</intent-filter>
</receiver>
compared to using
<receiver android:name="com.amazon.device.iap.ResponseReceiver">
<intent-filter>
<action
android:name="com.amazon.inapp.purchasing.NOTIFY"
android:permission="com.amazon.inapp.purchasing.Permission.NOTIFY"/>
</intent-filter>
</receiver>
If I use the first version in android manifest, then the app just crashes on start
Just purely for the record Htcls,
Since about 2015 Unity3D now has
in-app purchase built-in, as a integrated feature of Unity.
It is incredibly easy to use, compared to any previous approach for IAP/IAB.
https://docs.unity3d.com/Manual/UnityIAP.html
https://unity3d.com/learn/tutorials/topics/analytics/integrating-unity-iap-your-game
It is completely free and completely built-in to Unity.
This has been one of the most significant changes to App industry in some years.
Previously, achieving IAP/IAB (Apple/Google) was a HUGE effort on game titles. (The Prime31 plugins were popular for this.) Often it was more of a chore than making the actual game. It can now be achieved relatively simply WITH NO PLUGINS AT ALL inside Unity.
At this point it would be extremely unusual to use any other approach for IAP/IAB. It is an incredible advance and huge time saver that it is now built-in to Unity.
Regarding
Amazon...
store coverage, follow the thread here
http://forum.unity3d.com/threads/unity-iap-store-guides-amazon-apple-google-play-windows.372647/
https://docs.google.com/document/d/1QxHRo7DdjwNIUAm0Gb4J3EW3k1vODJ8dGdZZfJwetYk
Unity staffer "nicholasr" and others are actively answering all questions on the topic.
Consider this extremely simple code base which shows how the built-in IAP/IAB works
http://forum.unity3d.com/threads/unity-iap-store-guides-amazon-apple-google-play-windows.372647/page-3#post-2565610
Experimenting with Mobile Chrome apps API: ( https://github.com/MobileChromeApps/mobile-chrome-apps )
What I'm trying to achieve is the registering of my chrome alarms without having to crudely start the apps' main activity as this causes a bad user experience.
The challenge:
I have specified a chome.alarm which gets successfully registered when I open the app ('cca run android ' for example). These alarms are specified in a background.js file, which is declared as a background script in the manifest.json file.
I wanted these to be registered automatically on boot, therefore I implemented a background service and thought I could simply call the app to register the alarms specified in the background.js file. However, the only way I can find thus far to achieve this, is via a call to launch the apps main activity via an Intent from within the background service as explained in more detail below.
On boot, my background service simply invokes:
//Launch main activity..
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.company.appname");
startActivity(LaunchIntent);
The above launches the app into its main activity and the aforementioned chrome.alarms are registered as desired. Happy days! A massive downside to this, of course, is that no user wants the full blown main activity window to open on boot.
Please advise if there is a less clunky way to have the chrome.alarm specified in background.js registered at boot by a background thread. I do not wish to open the mainActivity of the app, yet this is currently the only way thus far I can see to get them to be registered. It is preferable not to register these alarms from within the Android SDK as I intend to stay as close to using web APIs and want to use background.js as the hook to do this keeping things in-line with chrome web apps as-well-as the android platform.
What I have done:
A cca (chrome mobile web app) app which registers a background service natively (I extend BackgroundService) as a plugin and register this to run at boot time. This is the only 'native android code' in order to load the app at boot-time.
Upon booting android, this background service then simply issues a startActivity(LaunchIntent) in order to open the app. In doing so, my chrome.alarm specified in my background.js file get registered successfully. If I don't do this, my chrome alarm specified in background.js do not get registered until I manually open the apps main activity. Therefore I use the backgroundService to open the apps main activity.
This is not at all ideal, I would simply like to somehow have my chrome.alarms registered without crudely having to launch the apps main activity window.
Is there a call which I can place in my BackgroundService to have only the chrome.alarms contained in my background.js file read and registered to fire?
Thank you for your time.
First, thanks for using Chrome Apps for Mobile! (Note: I work on the project)
Sorry that our current bootstrap is "crude" and "clunky", and we agree that it is. You can track this issue for progress on our effort to replace our current Background-scripts-embedded-in-main-Activity-webview strategy with a real background service and multiple window support. Basically you've summarized exactly our plan and existing limitations.
This work is actually scheduled for the near term, and will certainly be done before the end of the year.
As well as chrome.alarms, this feature is quite important for chrome.gcm and chrome.tcpServer (among other reasons).
I'm in the process of porting an app originally developed on iOS to Android. I'm trying to accomplish the following:
every time the app is started, call the start() method on a Manager class
every time the user leaves the app, call the stop() method on the same Manager class
every time the user comes back to the app (resuming from idle), call the start() method on the Manager class
The so-called Manager class handshakes with a server on the Internet and needs to do a variety of book-keeping activities every time the user the user enters and leaves the app.
Whereas iOS enables you to subclass the UIAppDelegate class and have code that runs when the app starts, ends, or resumes from idle, it seems Android doesn't have an equivalent approach. Instead, these are the options with Android:
1) Activity class: methods for every time an Activity (view) is created, stopped, or resumed
2) Application class: onStart and onDestroy for every time the app is started or killed
3) Service mechanism to create a background task that can be used to perform long-living operations in the background while the app is active or even while its not active
None of the above align real well with what I'm used to in iOS. Option 1 would require every Activity in the app's view hierarchy to have code that runs when the app starts/stops/resumes. Of the 3, I sense option 3 is more relevant. I'm just not entirely clear how I could start/stop a service in Android as the user starts/stops/resumes an app without regard to the specific activity they're on at the time.
I would appreciate input from Android developers or developers that work on both iOS and Android.
The so-called Manager class handshakes with a server on the Internet and needs to do a variety of book-keeping activities every time the user the user enters and leaves the app.
This might be a valid design pattern on iOS -- I have no idea. It is not a valid design pattern on Android. You don't "leave the app" on Android any more than you "leave the app" in a Web app. "Leave" is determined mostly as "you didn't come back in a while" in both Android and Web apps.
2) Application class: onStart and onDestroy for every time the app is started or killed
Note that the method is onTerminate(), not onDestroy(), and it actually never gets called. The Application object is created when the process is and lives until the process is terminated outright.
Its just not entirely clear how I could start/stop a service in Android as the user starts/stops/resumes an app without regard to the specific activity they're on at the time.
You might elect to use a service for doing the "handshaking" -- in fact, that's probably likely.
However, there is nothing built in for "leave the app". I would strongly encourage you to simply get rid of the concept entirely.
If not, you're welcome to rig up a service that is notified on each onPause() and onResume(), does the bookkeeping to see if there are any live activities, and if there hasn't been for X period of time, does your "leave the app" logic, then shuts down. You'd also trigger the "leave the app" logic in onDestroy(), if the service is shutting down at OS request vs. your own shutdown request. This is not 100% guaranteed to work -- users can force-stop your service and the OS can kill the process with impunity.
If you want to avoid duplicating code in all your Activities, why not have 1 subclass of Activity with the common code, and have the other Activities subclass that?
You can track activity lifetimes using a variety of mechanisms, including setting/clearing SharedPreferences in onPause/onResume, or use a singleton with reference counting.
Hope this helps,
Phil Lello
I am trying to determine feasibility of certain features required in a (potential) project. I am not (yet) looking for a how-to, just a can-do. I apologize for any vagueness and ignorance: the former due to an NDA that makes Apple's NDA look like GPL, and the latter due to the fact that I have no iPhone or MAC experience.
I do have a solid understanding of objective-c and interface builder (going back to NextStep) and some PDA development experience, so I'll probably understand the answers, even if my questions are naive. I have done a bit of browsing, so I know some buzzwords.
I can't go into detail about the actual project, but I have come up with a lame analogy.
a large number of users in the same room are asked to complete task(s) in the app (say a puzzle)
they are under supervision, but the monitor cannot watch them all closely
they are not allowed to leave the application until done.
they cannot send/receive phone calls or messages during the task.
the monitor receives notification of various steps during the task
the monitor is notified when the task is completed, or the app is exited
the app sends a heartbeat, so the monitor also knows if signal is lost
Jailbreak is not an option.
The app should also work on iPod Touch.
So the things I need to do that seem dicey to me are
can I turn off (or require the user to turn off) phone and sms but still be able send http to my server
can I prevent an app from being switched out (even if, say an alarm app triggers or the phone rings).
failing prevention, can I at least detect any of these events and notify my server.
failing notification, can I record the event for the monitor to check later.
The user will be aware (and in fact welcome) these restrictions. It's a trust issue - the user must not seek help or use a helper app to solve the puzzle, and wants the monitor (and other contestants) to know that he did not. It's feasible for the user to click on an "OK, I understand and approve" screen at the beginning, but not for each communication to the server.
The app would only communicate with a central server (run by my company) - the monitor would not be able to buy the server software, and the url's of the server would not be user (or monitor) modifiable.
Hey! This looks like an app for taking exams. Not what I am doing, but that would be cool too!
EDIT --
I changed the title and am adding a few more parts to the question, based in part on mmc's answer. The App may run in an offline mode that would have to do the following:
So using the exam analogy, the user off line experience would be something like this
Launch App
App download test questions, registers start time, etc.
Turn off phone (if app can't do it by itself)
Disable any app that might interrupt my App (can app do this?)
Resume and Take Test
Indicate test done (or finish last problem).
Turn on phone (if app can't) and restart App (if needed).
App uploads test results and log of any interruptions.
So the question becomes
Am I sure that I at least get to log any interruption I can't prevent
can I know the cause of the interruption (phone answered, alarm launch, user initiated)?
can the user be prevented from modifying the log
can I know what other Apps are running when I start? (to guard against a daemon that occasionally displays a hint or something.
I would still like to run with real time uploads, so a few other ideas come to mind.
If I can reliably detect and record that the phone or another app was used, that might be almost as good as preventing it.
Can the user prevent the phone from ringing even if it's on (eg. call forward + ringer off)
Can my app know if the ringer is off
Same question for sms messaging
If I can't block it, can the user just ignore (silent) call or message and not leave my App. Would my app know that?
Sounds like you might be better off doing away with the phone, and making it exclusive to the iPod Touch.
You've nailed your trouble spots.
There is no way to disable phone functionality, and at the same time maintain network functionality of any type (3G, WiFi, or bluetooth) If you disable the phone operations with Airplane mode, all of them are disabled.
There is no way to prevent the Home button from returning you to Springboard
You can notify a server of a premature app interruption (there is an applicationWillTerminate: method on your app delegate) but is not reliable. If the operation takes too long, your app will be forcibly terminated.
You could write to the local file system that a premature interruption happened, and this would be far more reliable, as this operation would be much faster.