[TOOL] Augmented android code snippets in web pages - Android Q&A, Help & Troubleshooting

A new extension for Chrome, livecode by Codota, augments android code snippets in web pages.
Livecode makes important Java source code elements interactive:
highlights calls to android APIs and shows the relevant docs in neat bubbles
finds related real-world code examples from GitHub
warns when a deprecated API is used in the snippet
Codota livecode is available (for free) at the Chrome Web Store, currently working in StackOverflow for android standard APIs. Support for additional sites and platforms is on the way.
Check it out at codota.com/livecode
It's free, would be very happy to hear what you think...

Related

I need some OOP advice

I'm developing an app for my college capstone project. It's an app for building contractors that has three basic functions. It allows them to create a project (project object), create a visit for the project where they can enter notes about the visit (visit object) and take pictures during the visit (picture object). At the conclusion of the visit they can then send an email with the notes and pictures to their boss, client, etc. My design consisted of those three objects: Project, Visit, and Picture.
I originally designed this last March and then another class, Java 6 which required I pass the Java certification test, kicked in. I finally passed the certification and am working on completing the project. Right now I have the following objects:
DbAdapter - parent class for handling the tables
ProjectDbAdapter - child class for handling the Project table
ProjectListActivity - class for displaying the Projects and providing editing and selection of a project
ProjectEditActivity - class for editing the Project fields
ProjectShowActivity - class the displays a project's information and allows options for editing the project and creating a visit
I'm having a problem in that if I click on a project in the ProjectListActivity screen, to open the project in the ProjectShowActivity screen I don't have the information, rowId value, to pass to the ProjectShowActivity to query the database to display the project record.
Based on my design, I should have a Project object that I can pass but I haven't implemented that yet and I don't know if I need to.
So, I'm looking for opinions and advice. Do I need to have a Project object or should the ProjectListActivity serve the same purpose and by the same token, do I need a Picture and Visit object or will the corresponding activities serve the same purpose.
Thanks

How to identify requests from quick apps on an HTML5 page

How to identify requests from quick apps on an HTML5 page so that the service logic will not instruct users to download an app?
The web component of a quick app uses the same standard HTML execution environment as browsers such as Google Chrome and Safari. When an HTML5 web page is loaded, the User-Agent attribute is reported to the server. The HTML5 web page can obtain the User-Agent object of the current execution environment through the JavaScript function. Therefore, you can set the User-Agent attribute for the web component to identity requests from quick apps.
The implementation procedure is as follows:
1. In the quick app, set the User-Agent attribute of the web component to default.
Code:
<web id='web' src="{{websrc}}" allowthirdpartycookies="true" useragent="default"></web>
2. On the HTML5 page, check whether the window.navigator.userAgent object contains the hap keyword. If yes, the request is from a quick app.
Code:
if (window.navigator.userAgent.indexOf("hap") >= 0) {
// The request comes from a quick app.
}
For details about Huawei developers and HMS, visit the website.
https://forums.developer.huawei.com/forumPortal/en/home?fid=0101246461018590361

How Can I Integrate HUAWEI Ads into a Huawei HTML5 Quick Game?

Symptom:
Currently, no ad API is provided for an HTML5 quick game. How can I integrate HUAWEI Ads into my quick game?
Analysis:
Currently, HUAWEI Ads supports only quick apps and runtime quick games, but not HTML5 quick games. You can use a two-way communication mechanism between the web component on the UX page of a quick game and the HTML5 web page of the game to integrate HUAWEI Ads into an HTML5 quick game. The onMessage lifecycle function on the UX page receives messages from an HTML5 page, calls the ad API of quick apps to obtain ad information (only available for native ads and rewarded video ads), and sends the obtained ad information to the HTML5 page through this.$element(‘web’).postMessage({ message: JSON.stringify(result) });.
Solution:
It is recommended that the ad creation and ad API request processes be separately encapsulated in different functions, instead together in the onInit or onMessage lifecycle function. This is because the onInit function is called during page initialization, which implements quicker loading, but it is not suitable for processing complex logic; the onMessage function is used to receive character strings passed by HTML5 pages. After you add a judgment branch, the corresponding function is called to perform specific ad processing.
Note: Currently, the quick app framework supports the creation of ad objects only in the onInit function, but not in functions such as onMessage. Keep the position of the code block unchanged.
For more sample code, you can refer to this site.
https://gist.github.com/Mayism/0a9f12438da0e86f06594e01e7643895
For more FAQs and cases about HUAWEI Ads integration, visit the following link:
https://developer.huawei.com/consumer/en/doc/development/quickApp-Guides/quickapp-access-ads-kit

HMS Toolkit Makes Integrating HMS Core Kits Effortless

Curious about how to integrate HMS Core kits into your apps? Or how to convert your apps integrated with third-party mobile services? Want the quickest and simplest way to release them on HUAWEI AppGallery?
Introducing HMS Toolkit.
This IDE plugin provides tools such as Getting Started, Configuration Wizard, and Repository and is designed for every stage of development: creation, coding, debugging, testing, releasing, and quality analysis. Armed with HMS Toolkit, you too can develop your own HMS Core-integrated apps in Android Studio and release them at lower cost and higher efficiency.
Every development phase, faster and easier
Getting Started demonstrates each HMS Core kit.
Configuration Wizard walks you through all the necessary settings, so no more looking up the manual or switching tools. Configure multiple kits at the same time, for different scenarios, so no more four-hour jobs – now just 5 minutes.
Repository shows you SDK version, package size, and usage to make integration and version a one-stop-shop. Automatically add an SDK library dependency after you select the library, get the latest SDK version, and upgrade the SDK with just one click.
Coding Assistant offers HMS Core API descriptions and sample code and templates by scenario. Drag and drop to generate and configure code, and get automatic issue warnings and recommendations.
Convertor helps you move from third-party APIs to HMS APIs. Convert your source code either with Add HMS API (add code to call HMS APIs to match third-party APIs so both can be called as needed), or To HMS API (replace code to call third-party APIs with code to match HMS APIs so only HMS APIs can be called).
Cloud Debugging uses a remote real device to quickly locate and resolve problems. Currently, choose from various Huawei devices if you're in the Chinese mainland, Russia, Asia Pacific, and West Europe. Quickly access the nearest site for single-step or ADB debugging. Drag and drop to upload files, zoom in and out onscreen, and toggle definitions between smooth, SD, and HD on the remote real device as needed.
Cloud Testing tests your app in one click to quickly detect problems on any device. Get screenshots for compatibility, stability, performance, and power consumption.
Publish to AppGallery Connect makes uploading easier to do from the IDE. Choose to upload either the packaged APK of the current project (default) or a local package, and its parameters will be checked against the release requirements. Once it's uploaded, you'll be prompted to access the HUAWEI AppGallery Connect release page.
HMS Toolkit also allows you to generate an API or demo project in one click for quickly verifying and calling the image classification model in your app.
Easy to install
Start Android Studio, go to File > Settings > Plugins > Marketplace, search for HMS Toolkit, and click Install. Or sign in and get it on the HUAWEI Developers official website.
HMS Toolkit will continue to be optimized to help you and other developers around the world create a smart life for users.
If you have any questions, please submit a ticket. Huawei technical support will reply to you as soon as possible.
For more information about HMS Toolkit, go to >>
For how to quickly integrate each kit using HMS Toolkit, go to >>
For more operation tutorials, go to >>
For more details, you can go to:
l Our official website
l Our Development Documentation page, to find the documents you need
l GitHub to download demos and sample codes
l Stack Overflow to solve any integration problems
Very useful sharing.

How to Target Ads Precisely While Protecting User Privacy

Background​
When using an app, if pop-up ads keep appearing when we browse app pages but we are not interested in the advertised content, not only will our browsing experience be negatively affected, but we will also quickly become tired of the advertised content. Unwanted ads are usually annoying. Aimless ad targeting and delivery will result in the wrong ads being sent to users and cause poor ad performance.
So, as publishers, how do we guarantee that we can deliver ads to audiences who will be interested in them and how can we decrease users' resistance to advertising? The answer is to collect information about the user requirements of your target audiences or to really know them, and to do so in a way that causes the least annoyance. But when a user is unwilling to share their personal data, such as age, gender, and interests, with my app, placing an ad based on the page that the user is browsing is a good alternative.
For example, a user is reading an article in a news app about the fast-paced development of electric vehicles, rapidly improving battery technology, and the expansion of charging stations in cities. If the targeted advertising mechanism understands the context of the article, when users continue to read news articles in the app, they may see native ads from nearby car dealerships for test driving electric vehicles or ads about special offers for purchasing electric vehicles of a certain brand. In this way, user interests can be accurately discovered, and publishers can perform advertising based on the keywords and other metadata included in the contextual information of the app page, or any other content users are reading or watching, without having to collect users' personal information.
But I can't integrate these features all by myself, so I started searching for tools to help me request and deliver ads based on the contextual information on an app page. That's when I had the great fortune to discover Ads Kit of HMS Core. Ads Kit supports personalized and non-personalized ads. Personalized ad requests require users to grant the app access to some of their personal information, which may not be palatable for some users. Non-personalized advertising, however, is not constrained by this requirement.
Non-personalized ads are not based on users' past behavior. Instead, they target audiences using contextual information. The contextual information includes the user's rough geographical location (such as city) authorized by the user, basic device information (such as the mobile phone model), and content of the current app or search keyword. When a user browses a piece of content in your app, or searches for a topic or keyword to express a specific interest, the contextual ad system scans a specific word or a combination of words, and pushes an ad based on the page content that the user is browsing.
Today, data security and personal privacy requirements are becoming more and more stringent. Many users are very hesitant to provide personal information, which means that precise ad delivery is becoming harder and harder to achieve. Luckily, Ads Kit requests ads based on contextual information, enabling publishers to perform ad delivery with a high degree of accuracy while protecting user privacy and information.
Now let's take a look at the simple steps we need to perform in order to quickly integrate Ads Kit and perform contextual advertising.
Integration Steps​
1. Ensure that the following prerequisites are met before you integrate the Ads Kit:
HMS Core (APK) 4.0.0.300 or later should be installed on devices. If the APK is not installed or an earlier version has been installed, you will not be able to call the APIs of the Ads Kit.
Before you begin the integration process, make sure that you have registered as a Huawei developer and completed identity verification on HUAWEI Developers.
Create a project and add an app to the project for later SDK integration.
2. Import the Ads SDK.
You can integrate the Ads SDK using the Maven repository.
That is, before you start developing an app, configure the Maven repository address for Ads SDK integration in your Android Studio project.
The procedure for configuring the Maven repository address in Android Studio is different for Gradle plugin versions earlier than 7.0, Gradle plugin 7.0, and Gradle plugin versions 7.1 and later. Configure the Maven repository address accordingly based on your Gadle plugin version.
3. Configure network permissions.
To allow apps to use cleartext HTTP and HTTPS traffic on devices with targetSdkVersion 28 or later, configure the following information in the AndroidManifest.xml file:
Code:
<application
...
android:usesCleartextTraffic="true"
>
...
</application>
4. Configure obfuscation scripts.
Before building the APK, configure the obfuscation configuration file to prevent the SDK from being obfuscated.
Open the obfuscation configuration file proguard-rules.pro in your app's module directory of your Android project, and add configurations to exclude the SDK from obfuscation.
Code:
-keep class com.huawei.openalliance.ad.** { *; }
-keep class com.huawei.hms.ads.** { *; }
5. Initialize the SDK.
You can initialize the SDK in the activity, or initialize the SDK by calling the HwAds.init(Context context) API in the AdSampleApplication class upon app launch. The latter method is recommended, but you have to implement the AdSampleApplication class by yourself.
6. Request ads based on contextual information.
The SDK provides the setContentBundle method in the AdParam.Builder class for you to pass contextual information in an ad request.
The sample code is as follows:
Code:
RewardAd rewardAd = new RewardAd(this, rewardId);
AdParam.Builder adParam = new AdParam.Builder();
String mediaContent = "{\"channelCategoryCode\":[\"TV series\"],\"title\":[\"Game of Thrones\"],\"tags\":[\"fantasy\"],\"relatedPeople\":[\"David Benioff\"],\"content\":[\"Nine noble families fight for control over the lands of Westeros.\"],\"contentID\":[\"123123\"],\"category\":[\"classics\"],\"subcategory\":[\"fantasy drama\"],\"thirdCategory\":[\"mystery\"]}\n";
adParam.setContentBundle(mediaContent);
rewardAd.loadAd(adParam.build(), new RewardAdLoadListener());
Conclusion​Nowadays, advertising is an important way for publishers to monetize their apps and content, and how to deliver the right ads to the right audiences has become a key focus point. In addition to creating high quality ads, significant efforts should be placed on ensuring precise ad delivery. As an app developer and publisher, I was always searching for methods to improve ad performance and content monetization in my app. In this article, I briefly introduced a useful tool, Ads Kit, which helps publishers request ads based on contextual information, without needing to collect users' personal information. What's more, the integration process is quick and easy and only involves a few simple steps. I'm sure you'll find it useful for improving your app's ad performance.
References​Development Guide of Ads Kit

Categories

Resources