Phonegap Local Notification Plugin for Android - android

I'm working on a "Reminders" application on Android using Phonegap[Cordova 2.2].
The user enters a specific date for his reminder and I'm supposed to notify him on time.
I used this plugin to Just show a notification in the status bar & they are working fine.
But I want the notifications to show at specific times. Is there some method to do it ?
I found this plugin that's supposed to do what I want but it's not working, it shows errors at :
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
The import com.phonegap.api.Plugin cannot be resolved
So, how can I fix this error ? I know it might be easy, but I never made native Android Apps before so I'm kind of confused.
Thanks

Looks like a difference between 2.0.0 and 2.2.0, and like the plugin needs updating.
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.PluginResult;
This should give you a jumping off point:
http://docs.phonegap.com/en/2.2.0/guide_plugin-development_android_index.md.html#Developing%20a%20Plugin%20on%20Android

For the new Phonegap Release you must also change some stuff:
The LocalNotification class must "extends CordovaPlugin" now
Import classes like eomer says
The execute method of LocalNotification.java must return a boolean now
Change all return arguments that are affected (from PluginResult) to boolean of your choice
Get the context in a new way ctx = this.cordova.getActivity(); and give it the ...AlarmHelper(ctx)

Related

Appium Native View, how to click the button to go back to the previous screen

I am pretty new to Appium, using UIAutomator2. Following instructions on the links:
[https://discuss.appium.io/t/click-back-button-on-android-device-in-java/6817/3][1]
[https://discuss.appium.io/t/click-back-button-twice-in-android-7-using-appium-uiautomator2/20368][2]
[https://stackoverflow.com/questions/30801879/how-to-automate-the-android-phone-back-button-using-appium][3]
I have tried all the options offered in these articles:
driver.pressKeyCode(4);
helper.driver.pressKeyCode(187);
driver.back();
driver.navigate().back();
If I add the imports
import io.appium.java_client.android.nativekey.AndroidKey;
import io.appium.java_client.android.nativekey.KeyEvent;
and I try
driver.pressKeyCode(AndroidKeyCode.BACK);
Eclipse tells me that the method is undefined...
But none of them have worked. Is there anything I need to import or any additional classes I need to create? My driver only has methods for testing, such as close(), equals(), execute(), findElement()... but nothing like back(), or pressKeyCode() or navigate()(this one, probably, because it is not webView)... So, when I try to just type any of those methods, Eclipse either suggests to add a cast, or to create a class...
Please, Can anyone give me some more details on how to do it?
The driver should be an Appium driver. And try to run on real device than emulators.
driver = new AppiumDriver<>(url, desiredCapabilities);

Android status bar show in Unty

I'm triyng to show the status bar in an Android phone using Unity. I have try this code:
void Start() {
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
But an error appear;
Assets/Scenes/Control/control.cs(15,34): error CS0103: The name 'WindowManager' does not exist in the current context
Does I need to call or import another package? Some could help me with this detail. Thanks in advance.
You cannot use Android Java functions directly in Unity. You can only use whats available in Unity C Sharp. Unity doesn’t understand the method. Suggested workaround, use a ‘Slider’ UI element and manipulate it in a custom c sharp script. Complicated workaround create a custom Unity Plugin which calls the native Android method (possible but complex).

visual studio android import cant resolved after update

I updated Visual Studio, then my Android project had errors such as import could not be resolved. It could not be resolved to a text type. The type could not be resolved. Then I created a new project with the same settings. However, it had the same errors. It does not work because of the code, but maybe it knows who knows the code here.
package com.Android2;
import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;
public class Android2 extends Activity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
/* Create a TextView and set its text to "Hello world" */
TextView tv = new TextView(this);
tv.setText("Hello World!");
setContentView(tv);
}
}
There is no problem with your code or imports...
I know it is hard work and a serious change when it comes to shortcuts, menus, overview, etc., but i would suggest to use android studio instead of visual studio if you only write android apps in java. I used visual studio too and switched to android studio.
Android Studio will give you more comfort than every other ide in programming android apps in java!
I know this problems you wrote about very well and had the same. Sry that this isnt a really answer of your problem and does not solves your concrete problem.
Tips for solving, you probably already know:
reboot your pc and visual studio if you not already did
delete caches or other from visual studio
rebuilt/clean your project
not easy, but reinstall visual studio
I hope i could help anyway!

How do I open GPS settings in android?

I am trying to navigate to the geolocation settings page, however, I get an error "ACTION_LOCATION_SOURCE_SETTINGS cannot be resolved or is not a field" in my code. I have searched everywhere, but couldn't find anything different from what I have done already.-
startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), 1);
I am running Android 7.0. Is there any other way to do this on my android version?
I think you are using wrong import
Use the below import and remove the previous one
import android.provider.Settings;
Or you can also try like below.
Intent settingintent= new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(settingintent);

Buildozer compiles apk, but it crashes on android

I am able to build an .apk, but after I install it on my android phone it simply crashes at startup. My thoughts for failing is that I am using 3rd party libraries e.g(beautifulsoup).
This is how my imports look in main.py:
from kivy.app import App
from kivy.properties import ListProperty, StringProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.scrollview import ScrollView
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
import time, os, random, urllib2, re, cookielib as cj
from bs4 import BeautifulSoup as bs
from functools import partial
I'm running mavericks 10.9.3
Does it have something to do with buildozer.spec file?
I've tried adding BeautifulSoup to app requirements, but it doesn't change a thing.
Any help would be appreciated.
I ran into this problem as well, but I was (apparently) able to get everything working fine with a workaround. Since it doesn't look like you posted a logcat, I'll assume you ran into the same issue I did.
Yes, you do need to list beautifulsoup4 as a requirement in your spec. From looking into bs4's code, it looks like bs4 is willing to use any of several "builders." It supports HTMLParser, html5lib, or lxml. I have no idea why we can't load HTMLParser, but it's actually the least preferred library of the three, and if it weren't for the fact that there's no try block around the import, it seems that everything would work fine (as long as one of the other parsing libraries was available).
With this in mind, I included one of the other libraries, and I decided to hack the import process so that Python would pretend _htmlparser loaded okay :)
This article was instructive: http://xion.org.pl/2012/05/06/hacking-python-imports/
The end result was something like this:
import imp
import sys
class ImportBlocker(object):
def __init__(self, *args):
self.black_list = args
def find_module(self, name, path=None):
if name in self.black_list:
return self
return None
def load_module(self, name):
module = imp.new_module(name)
module.__all__ = [] # Necessary because of how bs4 inspects the module
return module
sys.meta_path = [ImportBlocker('bs4.builder._htmlparser')]
from bs4 import BeautifulSoup
I also added html5lib to the requirements in buildozer.spec.
Now, is this the right way to solve the problem? I don't know. The best approach would probably be to request that the author fix it. It might be as simple as to put the import in a try block. Nevertheless, this is the approach I've gone with for the moment, and it is at least an interesting exercise, and a way to test your app until a better fix comes along.
Additionally, I should warn you that I only did this recently, so I can't 100% guarantee that it won't cause any problems, but at a minimum, it's worked well enough to get my app running and scraping the particular website I was interested in. Good luck!
I understand that this question is some years old. I think the answer #Will gave was fantastic but unfortunately, in my case, I couldn't use it because html5lib was too slow for what I was making. So this is for reference; for anyone who absolutely must use the built-in parser. It's not pretty but it's fairly manageable.
The issue
After much investigation, I nailed down the cause of the problem. In the buildozer log, I noticed that there was a problem compiling the _htmlparser file with the log reading as follows (with my project path replaced with <project-path>):
Compiling <project-path>/.buildozer/android/platform/build/dists/mypackage/private/lib/python2.7/site-packages/bs4/builder/_htmlparser.py ...
SyntaxError: ("(unicode error) \\N escapes not supported (can't load unicodedata module)", ('<project-path>/.buildozer/android/platform/build/dists/mypackage/private/lib/python2.7/site-packages/bs4/builder/_htmlparser.py', 135, None, 'data = u"\\N{REPLACEMENT CHARACTER}"\n'))
Because it was failing to compile, it wasn't being included in the built apk file. So I looked at the file and at the line that was causing the problem: data = u"\N{REPLACEMENT CHARACTER}" which should actually be replaced by data = u"\ufffd"
Quick-fix
Now the easy way out would be to modify the file right in the package. You could just edit the file mentioned in the error above which should, in theory, work but it's not recommended because every time the package gets re-installed or the code gets built from another machine the problem will be back.
Marginally better fix
It would be nice if the fix was all packaged into our code, so drawing inspiration from #Will's answer, here is the code you would need to put in before your bs4 import:
import sys
class ImportFixer(object):
def __init__(self, mname):
self.mname = mname
def find_module(self, name, path=None):
if name == self.mname:
return self
return None
def load_module(self, name):
import _htmlparser as module
module.__name__ = name
return module
sys.meta_path = [ImportFixer('bs4.builder._htmlparser')]
from bs4 import BeautifulSoup
The main difference is that you need to copy the _htmlparser.py file from the bs4 package to your current directory and fix the before mentioned line data = u"\N{REPLACEMENT CHARACTER}" with data = u"\ufffd"
Then, every time the bs4 module is imported, the import is magically intercepted and the local file is used.
Warning: if you ever update Beautiful Soup, you may need to use a more recent _htmlparser.py file in your project with the same fix made as needed.
Final comment
If I made some typos, grammar mistakes or didn't make sense at all, keep in mind that I worked most of the weekend to fix this and quite frankly I'm not thinking straight. Comment if you have any questions and I'll reply and/or edit my answer when I get a chance.

Categories

Resources