Is this possible? I have tried inflating and adding a layout that has android:keepScreenOn="true" and I have tried creating a WakeLock during onCreate() like this:
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"WatchFaceWakelockTag");
wakeLock.acquire();
These seem to have no effect. I do have the permission set in my wearable app manifest:
<uses-permission android:name="android.permission.WAKE_LOCK" />
There is (at the moment) no way of keeping the screen on. Believe me I've tried... And even asked people at Google working on Android Wear.
Related
Edit
I erased everything for clarity. as i am going to simplify my request for information:
What is best way to handle receiving messages from a wear on a mobile when the mobile is asleep or if app is not in the foreground?
During both these circumstances even though i send messages to the mobile from the wear, the mobile does not receive or process them. i do not know which.
if have read the following:
1) partial wakelocks - no good i dont want to really keep CPU awake
2) handler
3) broadcastreceiver
4) service
i do not know exactly what i should do in order to process messages with my app when app is not in the foreground and/or asleep.
If the onMessageReceieved() SHOULD process during sleep and or when app is not in foreground letting me know that would also be beneficial as right now i think it should not based on what i am seeing in my app.
Also i am using livelisteners instead of a listener service. is this my problem? if i instead switch to a wearablelistenerservice class will that solve my issues and work correctly?
i do this
#Override
public void onConnected(Bundle connectionHint) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Connected to Google Api Service");
}
Wearable.MessageApi.addListener(mGoogleApiClient, this);
}
instead of if i do this:
public class DataLayerListenerService extends WearableListenerService{
and put all my codes in there and then do this:
<service android:name=".DataLayerListenerService">
<intent-filter>
<action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
<data android:scheme="wear" android:host="*"
android:path="/start-activity" />
</intent-filter>
</service>
will that solve my not receiving messages problem when not in foreground and when phone is asleep? as this intent will act as a service that runs in the background?
You might want to check Keeping the Device Awake wherein it discussed different approaches that you can use such as keeping the CPU on.
As mentioned,
If you need to keep the CPU running in order to complete some work before the device goes to sleep, you can use a PowerManager system service feature called wake locks. Wake locks allow your application to control the power state of the host device.
You may find more tips and information in the use of wake locks from the given documentation.
Using a class that extends WearableListenerService and adding service to manifest worked for working while phone is off. Now i just need to implement and interact into the main feed to update data on the main screen
I'm trying to find out how to keep an Android service running after the starting app is closed. I've tried looking at samples for background services (e.g this one, and some on the Xamarin site) but in every case the service stops running if the minimised app is 'swiped' off the screen. I don't want the service to accidently stop like this, it should run continually until a confirmed stop is requested. The service does not consume much in the way of resources, just gets a GPS location and posts it to a website every 2 minutes.
By way of background, I am a newbie to Xamarin/Android, but have in the past created several successful services in Windows with C#
(Later)
One sample I tried did leave an item in the Settings list of running apps, but didn't actually perform any service tasks once swiped off the screen. Additionally there was no icon in the status bar. After doing some reading it seems that my androidmanifest file is missing a 'service' attribute (although none of the samples I tried have this); what I have now tried is this
<service
android:name=".LocationService"
android:icon="#drawable/icon"
android:label="#string/service_name"
>
<intent-filter>
<action android:name="android.service.LocationService" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
...but still no luck.
Have you had a look at the Xamarin sample here the source is here
They create a service like so:
[Service]
public class SimpleService : Service
{
System.Threading.Timer _timer;
public override StartCommandResult OnStartCommand (Android.Content.Intent intent, StartCommandFlags flags, int startId)
{
Log.Debug ("SimpleService", "SimpleService started");
DoStuff ();
return StartCommandResult.Sticky;
}
public override void OnDestroy ()
{
base.OnDestroy ();
_timer.Dispose ();
Log.Debug ("SimpleService", "SimpleService stopped");
}
public void DoStuff ()
{
_timer = new System.Threading.Timer ((o) => {
Log.Debug ("SimpleService", "hello from simple service");}
, null, 0, 4000);
}
public override Android.OS.IBinder OnBind (Android.Content.Intent intent)
{
throw new NotImplementedException ();
}
}
And start and stop it with this:
StartService (new Intent (this, typeof(SimpleService)));
StopService (new Intent (this, typeof(SimpleService)));
Also it sounds like you want a Sticky service Docs
When the system is under memory pressure, Android may stop any running services. The exceptions to this rule are services explicitly started in the foreground, which are discussed later in this article.
When a service is stopped by the system, Android will use the value returned from OnStartCommand to determine how or if the service should be restarted. This value is of type StartCommandResult, which can be any of the following:
Sticky – A sticky service will be restarted, and a null intent will be delivered to OnStartCommand at restart. Used when the service is continuously performing a long-running operation, such as updating a stock feed.
RedeliverIntent – The service is restarted, and the last intent that was delivered to OnStartCommand before the service was stopped by the system is redelivered. Used to continue a long-running command, such as the completion of a large file upload.
NotSticky – The service is not automatically restarted.
StickyCompatibility – Restart will behave like Sticky on API level 5 or greater, but will downgrade to pre-level 5 behavior on earlier versions.
Hope this helps.
Solved it now. The confusion was mainly due to many samples being out-of-date (using deprecated methods) and different suggestions for 'pure' Android projects and Xamarin ones. Certainly don't need to modify the androidmanifest file as I suggested above.
If anyone is trying to find something similar, my project is here.
Solving the initial issue has now raised some new questions, of course, but I will post separately about that if needed.
I'm new to both Android and Native Script. How do I open the Google Play Store inside my android app using Native Script. I've tried using web view and it works fine but I would like to open the Google Play Store using the Google Play Store app in the device.
Add permission application
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Add code into oncreate method
String url = "https://play.google.com/store/apps";
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(intent);
i have a querymobile/cordova app. i have a function with a for-loop. if i try it in my browser, it works perfekt, but on my tablet, he stops before the loop starts. i don't get an error in eclipse.
here's my code
function listPlan(){
alert("try to parse ics");
cal = $.parseIcs('sdcard/ical/'+aktFile);
console.log(cal);
alert('daten anzeigen');
for (var i=0; i<cal.event.length; i++) {
alert(i);
$('#roosters').append('<div data-role="collapsible"><h3>'+cal.event[i].dtstart[0].value+'</h3></div>');
}
$('#roosters').collapsibleset('refresh');
}
I'm not sure if you can access files on the sdcard using ajax calls.
Try with cal = $.parseIcs('file:///sdcard/ical/'+aktFile);
If it still does not work, maybe should you use the phonegap file api to get the file instead?
Edit:
I've performed a few tests to check access to files on the sdcard with ajax calls on Gingerbread, Jelly bean and KitKat using different urls:
'sdcard/test.txt' (like you're using in your initial code) : does not
work on my test devices
'/sdcard/test.txt' : works in gingerbread and jelly bean
'file:///sdcard/test.txt' : works in gingerbread and jelly bean
'file://sdcard/test.txt' : works in gingerbread but not jelly bean
none of those worked with kitkat (seems that the new webview added some restrictions).
So it seems that unless you tested with kitkat, using $.parseIcs should work.
Maybe the problem comes from some character encoding in your file? You could try to add some debugging code in the parseCalendar function to know why no event is added during the parsing.
Edit2
Surprisingly, on my kitkat device, xhr access to files on the sdcard requires to add the line <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> in androidmanifest.xml
I have been develop Phonegap android App. I put folder www in remote server, and in MainActivity(DroidGap) i loadUrl from server. I had config in Phonegap and App running in device ( load and show page from server). But problem when i send request by Ajax to server then it fail. It could not connect to any host. Please help me? Thanh you so much.
- MainActivity
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("http://172.16.3.198:8080/ServerMail/index.html");
}
- Config.xml
<access origin="*"/>
<content src="http://172.16.3.198:8080/ServerMail/index.html" />
the app does not have the internet permission. you can edit AndroidManifest.xml, and something like below:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.petro"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
Usually you have your 'site' files local to the app, not on a remote server, otherwise there is little point to Phonegap.
Here you might find that your URL is simply not reachable. A 172.16.x.x address is local to the network the server is hosted on, perhaps your phone is not on that network, especially if you are using 3G to connect.
Also, bare in mind that depending on the phone you use, you may be using an old version of webkit. As I've developed Phonegap apps, I have run into problems with jQuery 2 and older Android releases (2.1 for example). It seems to me that what you're doing is not a good use of Phonegap, and you might be better off using a shortcut instead.