I need some OOP advice - Android Q&A, Help & Troubleshooting

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

Related

[TOOL] Augmented android code snippets in web pages

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...

How Can I apply for promotion services for app?

HUAWEI AppGallery provides a convenient and quality platform for various app developers and is committed to building a fair, targeted, and efficient release channel to increase app exposure and download rate.
The promotion process is as follows:
Register as a developer
Identity Verification
Create Your app
Submit for App test
Top up
Create a promotion task
View promotion data (check result)
For more details: HUAWEI AppGallery Paid Promotion User Guide
Note: If this is your first top-up, sign in to the AppGallery Paid Promotion platform. Click the arrow next to your HUAWEI ID in the upper right corner and choose My promotion permissions. On the page that is displayed, click the Promoted apps tab page, find your app, and click Apply for promotion next to it. Perform the top-up again after Paid Promotion is enabled.

HMS Contact Shield SDK -1 Error Code Troubleshooting Procedure

Contact Shield is a basic contact diagnosis service developed based on the Bluetooth low energy (BLE) technology. Global public health institutions can authorize developers to develop COVID-19 contact diagnosis apps using Contact Shield APIs. These apps can interact with other devices while protecting user privacy to check whether a user has been in contact with a person tested positive for COVID-19. If so, the user will be notified and instructed to take relevant measures, effectively controlling the spread of the virus.
Working Principles​
1. The mobile phone of B broadcasts the DSC (Dynamic Sharing Code). The phone can generate a DSC collection based on the periodic key on each day, select a DSC based on the current time, and broadcast the DSC to surrounding devices through BLE.
2. The mobile phone of A receives the DSC broadcast by B. After scanning the DSC broadcast by the mobile phone of B, the mobile phone of A records the current timestamp and received signal strength indicator (RSSI), and stores the data in a local database.
3. If B is diagnosed as a COVID-19 patient, the app obtains authorization from B and uploads the periodic key within the virus incubation period (14 days by default) to the app server or the server specified by a public health institution. In this case, the periodic key of B is called the shared key.
4. The app of A periodically downloads the compressed package of periodic keys of the diagnosed user from the server and calls Contact Shield to perform contact diagnosis. Contact Shield deduces the DSC collection broadcast by the diagnosed person based on the periodic keys provided by the app.
5. During contact diagnosis, Contact Shield uses the DSC collection generated in 4 to match a record in the DSC data table of the last 14 days stored in the local database. After the matching is complete, Contact Shield generates a diagnosis report and notifies A of the contact diagnosis result through the app.
Based on the diagnosis report, A knows whether he or she has been in close contact with the diagnosed user and the potential contact risk level.
When the Contact Shield invokes the interface, the error code -1 is returned. There are many possible causes in this scenario. This section describes the troubleshooting procedure for this error code.
\Note: If the error code -1 is displayed, view the error log and search for the keyword HmsNearbyKit_sdk_ContactApiImpl. Generally, the log contains an error code with the actual error cause.
1. Developer have not applied for the Contact Shield permission (Error code 6004).
Cause 1:
Unlike other HMS SDKs, the Contact Shield SDK requires developers to send related information through emails to grant permissions.
For details about how to apply for the contact guard API permission, see:
https://developer.huawei.com/consum...equest-access-0000001058448610?ha_source=hms1
Cause 2:
The agconnect-services.json file in the local project does not match.
Check whether the agconnect-services.json file added to the local project is the same as the required agconnect-services.json file.
You can download the new agconnect-services.json file from the AGC official website and commission the project again.
For details about how to download the agconnect-services.json file, see:https://developer.huawei.com/consum...-integratesdk-0000001058897058?ha_source=hms1
2. The generated APK signature file (.keystore or .jks file) is different from the SHA-256 information configured on the AGC. (Error code 6003).​
The APK signature file must be the same as the signature configured on the AGC.
The configuration procedure is as follows:
https://developer.huawei.com/consum...ld-config-agc-0000001057648627?ha_source=hms1
3. When the API is invoked for the first time, the mobile phone is not connected to the network.​
When the contact guard API is invoked for the first time, if the mobile phone is not connected to the network, the error code -1 is returned.
In this scenario, ensure that the network connection is normal and invoke the Contact Shield API again.
​4. After the startContactShield() interface is invoked, the pop-up message is manually canceled.​After the startContactShield() interface is invoked, the following dialog box is displayed.
User must select Allow to invoke the Contact Shield API.
Note: The error code in the latest Contact Shield has been updated to 8015.
5. User do not have the location permission of the HMS Core APK.​When the startContactShield() interface is invoked, in addition to the pop-up for point 4, the dialog box shown in the following figure is displayed if you do not have the location permission.
User must select “ALLOW ALL THE TIME”to invoke the Contact Shield API.
Note: The error code in the latest Contact Shield has been updated to 8103.
To view the permission, choose Settings > Apps > Apps > Search HMS Core > Permissions > location.
6. When the putSharedKeyFiles() interface is invoked, the file format provided by the developer is incorrect.​When the putSharedKeyFiles interface of the Contact Shield is invoked, the transferred file in List<File> files is incorrect.
The format and generation method of this file are the same as those in Google's Exposure Notifications.
For more details, you can go to:
l Our official website
l Our Development Documentation page, to find the documents you need
l Reddit to join our developer discussion
l GitHub to download demos and sample codes
l Stack Overflow to solve any integration problems
Original Source

Huawei Ability Gallery — Card Ability

{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Hi everyone, I will explain Card Ability in this article. Article also includes general information for Huawei Ability Gallery. You can find and download a sample Card ability project at the end of Article.(If you want to test it, read requirements section before test).
What is Huawei Ability Gallery ?​HUAWEI Ability Gallery is Huawei’s unified platform for ability integration and distribution. It aggregates traffic from a wide range of devices in all scenarios and provides developers with a one-time integration and all-scenario distribution solution.
Note I : If you want to develop an Huawei ability, you need to have an Enterprise account otherwise Smart Service section on AGC cannot be seen. To learn How to register Enterprise account, visit link: Link
Note II : Developers in Team list cannot create ability even if They have enterprise account.
Note III :All Abilities can be seen in Huawei Assistant page. You can open or close page following steps : Settings -> Home Screen & Wallpaper ->Home screen settings -> Huawei Assistant today.
Devices for Ability Distribution​Services integrated with HUAWEI Ability Gallery can be distributed to 1+8+N devices in almost all scenarios and provide users with natural interactive services.
“1” : Smartphone.
“8” : tablet, smart TV, speakers, AR/VR, watch, head unit, earphones, and PC.
“N”: devices used in scenarios such as mobile office, smart home, sports and health, entertainment, and smart travel.
For example, the weather service integrated with HUAWEI Ability Gallery can be distributed to devices such as smartphones, tablets, smart TVs, head units, and watches through AI Voice.
Huawei Ability Integration Modes​Huawei Ability Gallery include 3 types of ability :
App Ability: Instant Access can access HUAWEI Ability Gallery via app abilities, which are presented by icon. Links for redirecting to an APK, RPK, or HTML5 page are provided by Developer.
Content Ability: HUAWEI Ability Gallery obtains data from developers’ servers through APIs and provides content abilities for Huawei products. Huawei products then present the abilities as defined.
Card Ability : Developers use quick app development technology to develop ability cards (including data processing and display logic), and abilities are displayed as cards.
Card Ability​Card ability presented by card has the following features:
The name and content of the ability are presented to users.
A user who taps the card will be redirected to the native app, quick app or HTML5 page.
More content is displayed to attract users, contributing to higher conversion rate.
Each users must subscribe Card ability to display Card ability in Huawei Assistant Page. Cards can be use without any app. Users just need to subscribe it to use.
Note : Each card has an widget id attribute which cannot be edited or deleted. Otherwise, the widget dragging and simulated preview functions will be unavailable.
Interaction Types of Card Ability​HAG includes three intents type. These are user ,event and resident events. Developers must configure at least one of them .
User Intents : A user intent is represented by one or more intents in the interaction model. Card ability can be triggered by Keywords , Voice and Images.
Event Triggers : An ability is triggered when event conditions (such as time and location) that you have set are met. When an event occurs, HUAWEI Ability Gallery pushes the ability card to users to display event-related information. To add an event, select an event category (Custom event or Preset event), set the event type, name, description, specify whether to push an event to a specified user, set the duration when the event card will stay visible on the screen, and finally set the display mode.
Resident Event Card : If you need a permanent intent card, just create it, with no need to push events. The card will be always available in HUAWEI Assistant.
For Detail Information About Interaction models of Card Ability , visit this page Link
Card Ability Design​HUAWEI Ability Gallery contains common template components and basic parameters, which must be used together with the UX specifications.
Developers use Huawei Quick App ide to design Card ability templates.
Note I : Unless You want to use predefined template, you can select empty template and then design it easily. You just need to look at this document to learn How to use ide.
There are many restriction to design card ability so Before start to design, Huawei Card design page must be checked. Link
Note II : Before you start card development, contact [email protected] for assistance and fill in the Service information registration table to ensure that your card complies with Huawei specifications.
Requirements to develop Card Ability​Before Developers start integration of HAG , They need to load some tools to design and test.
Huawei Quick App ide Packages
Huawei Quick App ide which is strong development tool is used to develop card ability. You can download here :
Note : Before load Huawei Quick App ide , You must install Node.js. Link
Huawei Quick App ide for Win64 : Link
Huawei Quick App ide for Mac : Link .
Installation Guide for Mac link
Huawei Quick App Loader
It is used to start and debug quick app and HAG development. Link
Card Ability Development​Card ability can be developed with Huawei Quick App ide. Developers use JavaScript, HTML and CSS to develop card ability. Quick app ide has many different template. If Developers want to use one of them , They can use and integrate their features. For instance they can get data from server and show these on Card ability to users like we did.
Note : Card development takes 12 days.
First step design or select card ability template. In our example I choose a template. To select a card template ,you can follow File > New Project > New Widget Project.
After create a card , developers can modify card ability appearance . In Our example, we change number of element list , images and content of card ability. In addition If users click “More Currencies button” , They will be redirected to related page of app. If you want to learn detail of design , visit following link
We need to create objects and variables to store data which comes from API .In our Card has on
JavaScript:
data: {
currencies:[
//Our models consist of 3 properties.name,currency rate and image.
//Images is stored base64 format in objects.
{"name":"GBP","rate":"0.00","imgUrl":"data:image/png;base64,..."},
{"name":"EUR","rate":"0.00","imgUrl":"data:image/png;base64,..."}
],
//It show that when Data was obtained
UpdatedTime:null,
//Our card title
currencyCardTitle:"Currencies",
//Our Button name
currencyCardButton:"More Currencies",
/*
these items will be displayed on card ability, Our design includes only two items.
If you want to add more items, you need to insert into here
*/
'dividings': ['newsandinformationtype_dividing', 'newsandinformationtype_dividing']
}
We need to send request to obtain data from service , We can use Fetch for this operation. Under line you can see how to use fetch .You can download all project to look at code scope from My GitHub repo which can be found at the end of page.
JavaScript:
import fetch from '@system.fetch'
...
module.exports = {
data:{ ... },
getDataFromAPI:function(e){
var that = this
fetch.fetch({
url: 'API url',
success: function (data) {
},
fail: function (data, code) {
}
})
}
}
Card ability includes a button which is called More Currencies. When users click it, they will be redirected to Currency Page which is in App. If developers want to create this feature, they need to use Router API and create a deep link.
JavaScript:
import router from "@system.router"
...
const currencyPageUri ="referenceapp://bank/currencies"//DeepLink of Currency Page
redirectToApp:function(){
//deeplink must be called to jump app page
router.push({uri:currencyPageUri});
}
Card Ability Configuration Steps​When Developers finish card development, they need to start an card ability in Smart service page. I said before If you want to create an ability, you need to have an Enterprise account.
This part includes only important section for Ability configuration.
When Start to configure ability , need to select a Site like Europe, Russia and Asia-Africa-Latin America(AALA).If you want to publish you ability all regions , You need to create same ability 3 times for different regions.
All ability includes a fulfillment which describes important settings. Fulfilment includes App URLs which users click to open app, qucikApp or H5 page.
Go to service button is important for card and content abilities. After Users click this, They will be redirected to service which may be app, quickApp or HTML 5 page.
Card Ability Test​After Finish Card development and configuration , Cards can be tested using Huawei Ability Test tool which can be downloaded from Huawei App Gallery or real device .
Developers just need to generate a QR code and then scan it with Huawei ability test tool.
If Real device test tool is wanted to use, user test list should be created on HAG configuration.
References​Card Ability : Link
Configuration Guide : Link
Test Guide : Link
Repo includes card ability example.
GitHub - SerkanMUTLU/Card-Ability-Example at dev
Contribute to SerkanMUTLU/Card-Ability-Example development by creating an account on GitHub.
github.com

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