I have never really had to ask a question here. Almost any question I can think of has already been asked and answered. Thus the reason I have never registered.
However, I have finally run across something that I cannot find an answer for. I assume it would be fairly simple.
I am trying to implement in app billing for an android project I am working on. I typically code in C# and use Unity to build the .APK.
However, this time I have to make modifications in Eclipse to some PreferenceScreens.
I have an xml file with some string-arrays set up for a ListPreference under my PreferenceScreen. These ListPreference values are then passed to UnityPlayer for a method. That's all set up.
I am trying to figure out a way to set up in app billing to trigger on selection of one of my list preference, or preference items.
I can probably figure a lot of it out on my own, but I need help with a function to do something pulling from a string value in the list preferences. Does this make sense?
I don't expect to be spoon fed, so if I can just get help on a few lines for this I would appreciate it. Of course I won't complain if anyone wants to write up a little 20 liner function to do it for me.
Thanks in advance,
John
** edit **
Here is the xml from the preferenceScreen I need to address with android In App Billing from Java
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:key="wallpaper_settings"
android:title="#string/wallpaper_settings" >
<!-- Ad Placeholder -->
<CheckBoxPreference
android:defaultValue="true"
android:key="rotate"
android:summary="#string/rotateSummary"
android:title="#string/rotateTitle" />
<CheckBoxPreference
android:defaultValue="true"
android:key="doubleTap"
android:summary="#string/doubleTapSummary"
android:title="#string/doubleTapTitle" />
<CheckBoxPreference
android:defaultValue="false"
android:key="swipeEmul"
android:summary="#string/simulateSwipeSummary"
android:title="#string/simulateSwipeTitle" />
<ListPreference
android:entryValues="#array/cameraValues"
android:defaultValue="MainCamera"
android:entries="#array/whichCam"
android:summary="#string/cameraSummary"
android:dialogTitle="#string/cameraTitles"
android:title="#string/cameraTitles"
android:key="whichCam"/>
</PreferenceScreen>'
This question is very generic, on an Android application you might do this by creating an Activity, then starting that activity from your preference "onClick" method and then, once the activity starts, you load all your in app billing stuff (showing a progress dialog) and finally present the "buy" dialog. Is this what you need?
Related
I am trying to set up the default value for the list preferences in my app, but I am having trouble with the default value, as when I try to run the app the default values that I chose in both list preferences are not being selected in runtime. This is my xml code:
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory app:title="#string/display_header">
<ListPreference
app:key="language"
android:title="#string/language_title"
app:summary="#string/en"
android:entries="#array/lang_entries"
android:entryValues="#array/lang_values"
android:defaultValue="#string/en"
/>
<ListPreference
app:key="display"
app:title="#string/display_mode_title"
app:entries="#array/display_entries"
app:entryValues="#array/display_values"
app:summary="#string/automatic"
android:defaultValue="#string/automatic"/>
</PreferenceCategory>
</PreferenceScreen>
I tried uninstalling and reinstalling the app but it did not work. I also checked that the string names that I used in the default value are correct, and I also made sure that the default value matches the one in the string array of entries. Please help me fix this problem
I think defaultValue is a number/index of the choice.
See this post.
I just found out that I had to replace the android:defaultValue line by app:defaultValue and I had to pass the corresponding value to the entry that would be the default value in runtime.
I am trying to follow the gcm tutorial from Googles docs. They say to call this method if Play Services are out of date:
GooglePlayServicesUtil.getErrorDialog(resultCode, activity, 9000).show();
That's fine, but it puts a dialog that says "This app won't run unless you update Google Play Services" with an "Update" button. I want to change the title and the message text. My users CAN skip the update, and the app will still run. They just won't get push notifications. How do I change the message of the dialog?
I would like to do something like:
Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(resultCode, activity, 9000);
errorDialog.setTitle("out of date");
errorDialog.setMessage("Please update or push notifications won't work. Thank you");
errorDialog.show();
You can override desired string value in your application's strings.xml like this. Simply add these lines in your strings.xml
For message on dialog
<string name="common_google_play_services_update_text" msgid="448354684997260580">This app won\'t run unless you update Google Play services.</string>
For title on dialog
<string name="common_google_play_services_update_title" msgid="6006316683626838685">out of date</string>
EDIT
You could find more information here
http://blog.elsdoerfer.name/2010/04/08/android2po-managing-android-translations/
and What's the meaning of attribute 'msgid' in strings.xml?
msgid is used in android internal strings for localization but I never found any documentation about it. Two reference I have as above. I believe if you remove the msgid still it would work, although I never tried it.
The source of this code is
android_sdk\extras\google\google_play_services\libproject\google-play-services_lib\res\values\common_strings.xml
I'm trying to extend the DialogPreference so I can have a NumberPicker for one of my
preferences. I've been reading:
http://developer.android.com/guide/topics/ui/settings.html#Custom
But I'm hitting an 'Error inflating NumberPickerReference' message. I think I know
why, but I'm not sure how to fix it.
My preferences.xml looks like:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<CheckBoxPreference
android:key="pref_alertsEnabled"
android:title="#string/alert_enable"
android:summary="#string/alert_enable_desc"
android:defaultValue="true" />
<NumberPickerPreference
android:key="perf_Timer"
android:title="#string/timer"
android:negativeButtonText="#android:string/cancel"
android:dialogTitle="#string/timer"
android:summary="#string/timer_desc"
android:dialogMessage="#string/timer_desc"
android:positiveButtonText="#android:string/ok"/>
</PreferenceScreen>
And in my projects src folder I have NumberPickerReference.java. I think the thing I'm missing is how to tell Android where to find NumberPickerReference class.
When preferences.xml is read in, I'm guessing it goes looking for the NumberPickerReference class, but doesn't find it.
Do I need to specify where to find the NumberPickerReference.class ? If yes, how do I do this ?
BTW, the app runs fine if I remove the <NumberPickerReferecnes> item from preferences.xml
Just add the path to that preference:
com.your.package_name.and_path.NumberPickerPreference
E.g.
<com.example.myapp.preferences.NumberPickerPreference
android:key="perf_Timer"
android:title="#string/timer"
android:negativeButtonText="#android:string/cancel"
android:dialogTitle="#string/timer"
android:summary="#string/timer_desc"
android:dialogMessage="#string/timer_desc"
android:positiveButtonText="#android:string/ok"/>
I am following developer.android to do their training. I am in the process of "Adding the Action Bar", however, i encountered a problem.
In the section "Respond to Action Buttons" here (http://developer.android.com/training/basics/actionbar/adding-buttons.html#Respond), the line "case R.id.action_search:" has error which says "action_search cannot be resolved or is not a field".
[Delete] In fact, the line "openSearch();" and "openSettings();" have red lines as well, saying "The method openSettings() is undefined for the type MainActivity". [/Delete]
(I know what is wrong here, I need to declare those two methods by myself.)
what should I do? Thx for the help first.
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
android:showAsAction="ifRoom" />
Firstly, the attribute android:id="#+id/action_search has no problem.
There are two things you need to do that the tutorial seems to have taken for granted
Add an image called "ic_action_search.png" to all the res/drawable directories in your project.
Add the definition for the string resource "action_search" which is being assigned to the android:title attribute. Open the res/values/strings.xml file and add
<string name="action_search">Search</string> over there.
Secondly,
The functions openSearch() and openSettings() need to be defined in the same class by you. Something like :
public void openSearch()
{
//Do something here.
}
public void openSettings()
{
//Do something here.
}
their functionality is not important for the tutorial as they are trying to show how you can control what happens when an option on the action menu is selected.
Go Project->Clean
It worked for me
I tried it and had the same problem. I removed android:icon="#drawable/ic_action_search" (instead of adding the images because I'm lazy) and added the action_search string in the resource file to make sure the menu file wasn't referring to anything that didn't exist. After that, I tried changing android:id to android:title because I saw that it had worked for you, and this was curious. It caused an error after saving, and so I changed it back. After changing it back and saving, the original error in the MainActivity.java file disappeared, and R.id.action_search was resolved. I think the problem is just that R.java is not being updated, and you have to basically hit it with a hammer by forcing an error and fixing it, at least in my case. I don't know why using android:title worked for you. Hope this helps somehow.
I've got few questions about Android and SCORM. In both areas I'm pretty new and I only spent one evening digging the web in search of some answers.
Topics I found were about synchronizing SCORM package with LMS but I do not need that. I'm just wondering how to PLAY (and just play, no need for any syncing or tracking) SCORM package on android device (Lenovo tablet with Android 4+ OS). If I try to make my own application which allows to browse local SCORM packages, will I be able to launch SCORM by using WebView component?
I found this tutorial:
http://support.scorm.com/entries/21826060-RSOfflinePlayer-Developer-Tutorial
which has section:
Playing Content and Syncing Results
where I found some interesting source code about configuring this WebView component in order to play SCORM content, but I'm not really sure if I need RSOfflinePlayer.jar for this.
I've also heard, that if device supports Flash, I will be able to launch SCORMs with Browser - is it true?
Maybe you know some application which can do that? Or library which could help?
Is there anyone with experience in:
1) Java SCORM API:
would paste URL, but I need more reputation
2) Celine
https://code.google.com/p/celine-scorm/
Any help will be appreacieted, not only by me but also by children with different kinds of diseases (we are just students trying to help them).
Javier is almost right. I will nonetheless try to explain this again. Maybe you will gather more information from this.
Every SCO is basically a zipped webpage. You have to unzip it and look for imsmanifest.xml, find the initial file in there (index.html, player.html, something like this). It will NOT be located under resources. You first have to look at Organizations > Organization > Item > Identifierref, which will give you an ID. Then you have to look at Resources > Resource with the above ID > href value. This is the file you're looking for.
Example (index.html is the file you need):
<organizations default="someorg">
<organization identifier="someorg">
<title>Some Title</title>
<item identifier="CourseItem01" identifierref="SCO_Resource_01" isvisible="true">
<title>SCO Title Here</title>
</item>
</organization>
</organizations>
...
...
<resources>
<resource identifier="SCO_Resource_01" type="webcontent" adlcp:scormtype="sco" href="index.html">
<file href="index.html"/>
<file href="SCORM_API_wrapper.js"/>
...
Once you found it, just open it in WebView and it'll try to connect to SCORM API in the parent window. You'll have to provide some dummy functions to fool it into thinking that it did connect to LMS and carry on as usual. Otherwise it will either fail or throw alerts at you.
I don't have any Android experience, but I have some experience working with SCORM.
To play a SCORM object, you need to open the right file inside the right environment, the right file is stated in the imsmanifest.xml file, that will be always in the top level of the zip package, you have to look for something like this:
<resources>
<resource identifier="546468" type="webcontent" href="index.htm" adlcp:scormtype="sco">
<file href="index.htm" />
</resource>
</resources>
This means that you have to open index.htm in the top level, in general you have to look for the first resource with adlcp:scormtype="sco" (if you need more details, read the SCORM spec).
When this page loads, it will look for the API object, it must be in the parent window, or parent frame, you will need a dummy SCORM API, something like:
function ScormAPIClass()
{
this.GetLastError = function (){return 0};
this.GetErrorString = function (param){return ""};
this.GetDiagnostic = function (param){return ""};
this.SetValue = function (element, value){
//you need something else here
return true};
this.GetValue = this.SetValue = function (element){
//you need something else here
return true};
this.Initialize = function (param){return true};;
this.Terminate = function (param){return true};
this.Commit = function (param){return true};;
this.version = "1.0";
}
window.API_1484_11 = new ScormAPIClass();
The SCORM objects will assume that you API works, so, if the set and get functions are not real this can generates errores depending on the object logic.
Also, I did not tested the code, is only to give you an idea of what you need.
I hope this help you.
First you have to understand structure of Scorm.
You can see Scorm package is a zip file containing several folders right and a manifest file.
First you have to unzip that zip package of Scorm and then you have to parse that imsmanifest.xml file and maintain two lists one containing titles and other addresses of html files corresponding to that title.
I have used sax2r2 parser to parse that manifest file and got that two array lists one containing title and other addresses of html files.
Later you just have to fill up you IOS list with titles array, and when user click on any title of that list get the position of list and retrieve the address of html files corresponding to that title from addresses array list.
finally you can open html file in webview of your IOS, make sure have enabled parameters required for open scorm html5 file.
In android I have enabled and set these values this is java code but it may help you.
WebViewClient webViewClient = new WebViewClient();
webView.setWebViewClient(webViewClient);
webView.clearCache(true);
webView.getSettings().setUseWideViewPort(true);
webView.setInitialScale(1);
webView.getSettings().setBuiltInZoomControls(true);
webView.clearHistory();
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setPluginState(PluginState.ON);
webView.loadUrl("file://" + open_scorm.scorm_path
+ open_scorm.scorm_name + "/" + open_scorm.href.get(0));
webView is used to open html/html5 files in android and i have enabled above settings in android, these settings are by default in android, may be in ios you just have to load that html file and dnt have to enable all these values.
In above you can see I am retrieving href.get(0) which is first html5 file of scorm.
In simple words you just have to unzip scorm , parse imsmanifest.xml file and get data of it and use it to open/parse scorm.