Can I combine these two apps (native and hybrid) into one app? - android

I have an app fully developped with Android Studio. I need to create a second app and this one I would like to do it with phonegapp. These two apps are related one to each other... so ideally I would like to combine them both in the same app... By combining I do not mean they need to work together. I would like them to be downloadad together (as the same app) and be able to go from one to the other withinn the app... so they can be completely two separate apps, but where the user would think it is only one app. I hope I am making myself well understood, The hybrid app uses the microphone with the Cordova plugin. At one time I thorugh about placing it with an iframe, but we would lose the microphone which invokes speech recognition Google native in Android, to convert it to text and pass it to edit text.
So my questions is:
Can I combine these two apps (native and hybrid) into one app?
Would the microphone with speech recognition to convert to text work well in both cases?

Yes, it was a bit of a pain to set up, but I have it working. I am not using PhoneGap, but I am using Construct along with the Cordova plugin, so it should be a similar setup.
First I took all of the web files generated by Cordova and placed them in the assets directory (if you do not have an assets directory you can just create one in the main directory). Then I used a WebView to display the content:
public class CordovaActivity extends AppCompatActivity {
private WebView mWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cordova);
mWebView = (WebView) findViewById(R.id.content);
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
settings.setAllowUniversalAccessFromFileURLs(true);
}
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
settings.setMediaPlaybackRequiresUserGesture(false);
}
mWebView.loadUrl("file:///android_asset/www/index.html");
}
#Override
public void onResume() {
super.onResume();
if(mWebView != null) {
mWebView.resumeTimers();
mWebView.onResume();
}
}
#Override
public void onPause() {
super.onPause();
if(mWebView != null) {
mWebView.pauseTimers();
mWebView.onPause();
}
}
}
The setJavaScriptEnabled(), setDomStorageEnabled() and setAllowUniversalAccessFromFileURLs() settings all had to be set to true or the content would not load. The last setting, setMediaPlaybackRequiresUserGesture(), was required to allow audio to play.
It will be a little more work to get the Cordova content to interact with the rest of the app though; you will have to use a JavaScriptInterface in order to do so.

1) Nothing is stopping you from having two apps that act as one (aside from the downloading part). They can "speak" to one another using dedicated Intents and share data using ContentProviders. You will have to take care of the case where one app is installed and the other isn't.
2) I don't see any particular issue with the the microphone in this scenario.
However, if I were you, I'd opt for using a single app if that is possible. I am not sure what are the phonegapp limitations for this kind of implementation though.

Related

Enable All Languages Font in an Application

My application is a simple web view type of app. It just loads a website in one page but I'm having a font issue where on some devices some languages are not supported, is there any solution for this situation?
My code is below:
public class MainActivity extends Activity {
private WebView web1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
web1=(WebView)findViewById(R.id.web);
web1.getSettings().setJavaScriptEnabled(true);
web1.setWebViewClient(new WebViewClient());
web1.getSettings().setBuiltInZoomControls(true);
web1.loadUrl("http://dcs-dof.gujarat.gov.in/live-info.htm");
}
First please make sure the charset attribute is correctly set in HTTP header or the meta field of the HTML page.
Besides, and the displaying may also depend on the fonts pre-loaded on the specific devices. Although by default most languages are supported in Android AOSP, but as far as I known some manufacturers will remove some characters/languages just in order to save up the disk spaces.
To tackle #2, A tricky way is to install/copy the fonts manually to your device under /system/fonts.

How to save cookies for my android web application

lets say I have an application for my University web site. Where user can navigate by pressing on screen button( Actually, what I did, I categorized everything in my main layout,where each button represents each fields, if any one presses myaccountStatus, then he will be directed to that specific link) However, my web site needs user name and password every time. Where I don't want my user to bother about this at all. So my question is, is there any way I can enable auto-log in?
My application has basic core web feature implemented(WebView, zoom, java-script enabled, some back, forward, stop, reload, favorite, save for offline reading) and everything is working fine, please help with the auto-log in problem.
So far I know, I can do this by saving cookies. But I have no Idea, how they look, what are they and how to handle those thing. So, please give me a step by step tutorial for this problem. Thanks in advance.
If your are using a web-view based approach (maybe something like cordova?) you could just use the local storage or the web sql standard for html5 apps: Tutorial for Web-Sql.
If you want to store cookies you have to enable them. I'm doing this in my Phonegap/Cordova application with this small Lines of code:
#Override
public void onCreate(Bundle savedInstanceState) {
// ... do whatever you want...
// this lines allow to set cookies
try {
CookieManager.setAcceptFileSchemeCookies(true);
} catch (Throwable e) {
}
// and the default stuff for phonegap/cordova to show a splashscreen and load the application
super.onCreate(savedInstanceState);
super.setIntegerProperty("splashscreen", R.drawable.splash);
// load the index url from config adding locale support.
super.loadUrl(Config.getStartUrl() + "?locale="
+ Locale.getDefault().getLanguage(), 4000);
}
I hope this helps.

Creating a Questionnaire in Android

Peace be on all of you!
I have to develop a questionnaire like small android app. There will be 10 questions with only 2 types of answers, i.e. either "Yes" or "No". When the user will answer all of the 10 questions, a report will be shown to user according to his answers.
Kindly tell me, how should I proceed? Do I need to use database (sqlite) or can work without it? and how should I start to develop this app?
I am new to Android.
Thank-you!
If you are new to Android, than use a web approach: Show a html page 1-10 in a webView and link it each other and finally the 10th is linked to an url, where you will do a http POST / GET with your collected 10 params. Exactly as how would you do in a "standard' web development. Also you can use several app to wrapp into Android app: Appcelerator, Phonegap and so on.
Here is a class which is a screen: (Android Activity)
public class Help extends Activity{
private WebView webViewHelp;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.help);
webViewHelp = (WebView) findViewById(R.id.webViewHelp);
webViewHelp.loadUrl("file:///android_asset/ui/help.html");
}
}
you need the help.xml build and placed into /res/layout/ folder.
Also write the help.html and place it into: /assets/ui folder and not android_asset and at is not file:///assets/ui/help.html!
in this case you have the starting point set up, than go and load with html links the next next next ... until is done, than pust url.
Somewhat easyer if you are doing in android ui development, and not web-like, but that need a bit more experience

Accessibility and Android WebView

Is Accessibility enabled for Android WebView? Can anyone tell how to make a WebView accessible?
The Android webview accessibility is enabled via javascript injection in Honeycomb and above (as pointed out by alanv). The user must enable it by:
Turning on Accessibility mode, including 'Explore by Touch' in 4.0+.
Enabling 'Enhanced Web Accessibility', or, on older devices, 'Inject Web Scripts'.
This works by injecting javascript into each loaded pages via <script> tags. Note that you will have to be careful, as not all content will play nice with this javascript, and the injection will fail in some edge cases.
You can extend the WebView class to implement Accessibility API methods.
http://developer.android.com/guide/topics/ui/accessibility/apps.html#custom-views
I also ran into this issue on 4.0 devices. I ended up placing a TextView on top of the WebView, making the TextView background and text transparent. The text content of the TextView being set to the content of WebView with all HTML tags stripped out.
A most inelegant solution, I know, but hey it works....
No, the WebView is not accessible from the built-in TalkBack service, at least as of Android version 4.0. Instead, blind users are instructed to use something like Mobile Accessibility for Android, which provides a spoken browsing interface. I would suggest making your content available to other processes, allowing blind users to view the content in their browser of choice. I did this by starting an intent to view the content:
public static void loadUrlInBrowser(Context c, Uri uri) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(uri, "text/html");
c.startActivity(i);
}
Alternatively, you can set the content description of the WebView. Note that this only seems to work in pre 4.0 versions of android. I've found that 4.0 devices keep either say WebView or nothing at all.
I know how to access web view content by Accessibility API, when AccessibilityNodeInfo.getText() is null or "null", call AccessibilityNodeInfo.getContentDescription().
simple code:
private String getTextOrDescription(AccessibilityNodeInfo info) {
String text = String.valueOf(info.getText());
if (isEmptyOrNullString(text)) {
text = String.valueOf(info.getContentDescription());
}
return text;
}
private boolean isEmptyOrNullString(String text) {
if (TextUtils.isEmpty(text) || text.equalsIgnoreCase("null")) {
return true;
}
return false;
}
getContentDescription() can get the web view content.
sorry for my poor english.

Android twitter connection/authentication intent bad formed?

I've been trying to connect to twitter through android for a while.
I'm currently using this api: http://kenai.com/projects/twitterapime/forums/forum/topics/13327-Twitter-API-ME-1-8-Now-with-OAuth-support
I used their exemple with my keys and everything connects without problem. So no problem with configuration.
But in my project which has exactly the same code I can't make it work.
I believe its related with the creation of a new Intent (also this is where the eclipse is point the error)
Im trying to use a custom layout but I don't know what do I need to change to make this specific Twitter layout to work. On main activity I have a button with this:
public void onClick(View v)
{
startActivity(new Intent(this,Twitter.class));
}
on twitter class
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//this.webView = (WebView) findViewById(R.id.webView1);
WebView myWebView = new WebView(this);
setContentView(myWebView);
authenticate();
}
private void authenticate()
{
WebViewOAuthDialogWrapper page = new WebViewOAuthDialogWrapper(webView);
page.setConsumerKey(CONSUMER_KEY);
page.setConsumerSecret(CONSUMER_SECRET);
page.setCallbackUrl(CALLBACK_URL);
page.setOAuthListener(this);
page.login();
}
what requirements/adjustments are needed to make/change to the Twitter activity?
I believe I need to change something in the intent-filter but I don't even understand the work of intents. I've been only making easy layouts.
Note that I also gave internet permissions already.
Looks like i was making 2 mistakes.
First i was trying to use "webView" variable in WebViewOAuthDialogWrapper instead
"myWebView" so it wasn't initialized...
Second looks like i forgot to put the order of which the external libraries were loaded....
So be sure to put external libraries on top in eclipse project.
Lost about 2 days with these problems... oh well

Categories

Resources