[SOLVED][Debug Help] Empty/White Activity (invisible UI controls) - Android Q&A, Help & Troubleshooting

Hello! I generated a very simple 2 activities app using Google's Android Studio, and the target is an Android 8.1 phone. The problem is that the main activity doesn't show the edit box and buttons (that are obviously visible in the Design page). If I start my login activity (in the onCreate() function of the main activity), the login activity UI is visible and the main activity UI is still not visible. If I single step debug the app, the main activity UI seems present (as no error is encountered). They are just invisible. I compared the XML of both activities, and couldn't find a different setting that would fix this problem.
PS: I could't find a solution in Google search either.
PS: I added a space to break the URL links below.
AndroidManifest.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http: //schemas.android.com/apk/res/android"
package="com.example.test2">
<application
android:allowBackup="true"
android:allowTaskReparenting="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="false"
android:theme="@style/AppTheme">
<activity
android:alwaysRetainTaskState="false"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:alwaysRetainTaskState="false"
android:label="@string/app_name"
android:name=".LoginActivity"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.test2.MainActivity" />
</activity>
</application>
</manifest>
activity_main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http: //schemas.android.com/apk/res/android"
xmlns:app="http: //schemas.android.com/apk/res-auto"
xmlns:tools="http: //schemas.android.com/tools"
android:id="@+id/containerMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="16dp"
android:paddingTop="16dp"
android:paddingEnd="16dp"
android:paddingBottom="16dp"
android:visibility="visible"
tools:context=".MainActivity">
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout"
android:layout_width="0dp"
android:layout_height="46dp"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="8dp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent">
<android.support.design.widget.TextInputEditText
android:id="@+id/textName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/TextNameHint"
android:visibility="visible" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="8dp"
android:clickable="true"
android:enabled="true"
android:focusable="true"
android:longClickable="false"
android:onClick="buttonClick"
android:text="@string/Button"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout>
MainActivity.java
Code:
package com.example.test2;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ToggleButton;
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Thanks in advance!

[SOLVED] [Debug Help] Empty/White Activity (invisible UI controls)
Even though the design view seemed fine to me, including constraints and all, something was off to make the UI controls invisible. To try to isolate the problen, I decided to delete the controls one by one, and then I started to see something.
So, I made a different UI design. :cyclops:

Related

[Q] SDK 4 Home Screen Widget - No Activity Found!

I am new to Android SDK,but I know JAVA a little.I am on SDK v4.The problem is that,I tried to make 'HelloWidget' Home Screen Widget (with just a text box),and when I try to run the project,the console gives me
Code:
No Launcher Activity Found!
The application will only sync the package to the device!
And my app is nowhere to be found in the AVD.I had tried putting the .MAIN and Launcher in Intent filter,but no good.Here are my files:
AndroidManifest.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="removed due to newbies are not allowed to post links"
package="ax.startup"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<!-- Broadcast Receiver that will process AppWidget updates -->
<receiver android:name=".AxStartup" android:label="AxStartup">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@layout/startup_info" />
</receiver>
</application>
</manifest>
main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="removed"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/txt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="HELLO WORLD"
/>
</LinearLayout>
startup_info.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="removed"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/txt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:text="ITS WORKING DUDE!"
android:minWidth="146dip"
android:minHeight="72dip"
android:updatePeriodMillis="10000"
android:initialLayout="@layout/startup_info">
<requestFocus />
</EditText>
</LinearLayout>
Java file
Code:
package ax.startup;
import android.appwidget.AppWidgetProvider;
public class AxStartup extends AppWidgetProvider {
}
I followed the tutorial from helloandroid website.
And another strange problem is that when I long press on desktop,only options to change wallpaper is coming.There is no 'Add to Home Screen' or 'Widgets' or any other menu!!!

[Q] "UNINSTALL_SHORTCUT" does not work any more for android 4.0 (API 14 and above)

[Q] "UNINSTALL_SHORTCUT" does not work any more for android 4.0 (API 14 and above)
Hi,
The following code "UNINSTALL_SHORTCUT" works for
Android 2.3.3 (API 10) to Android 3.3 (API 13), but does not work any
more with Android 4.0 (API 14) or above.
The Toast message says it is removed, but actually it still exist and
the new one just place on top of the existing one. This creates
multiple shortcuts on top of each other.
Does anyone see the same issue I am seeing or there's other fix for
this with Android 4.0?
Thanks in advance for your help.
=================================
private void deleteShortCut(Context context) {
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.setClassName("com.example.androidapp",
"SampleIntent");
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.putExtra("someParameter", "HelloWorld");
Intent removeIntent = new Intent();
removeIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
shortcutIntent);
removeIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut
Name");
removeIntent.putExtra("duplicate", false);
removeIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
context.sendBroadcast(removeIntent);
}
private void addShortCut(Context context) {
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.setClassName("com.example.androidapp",
"SampleIntent");
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.putExtra("someParameter", "HelloWorld");
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut Name");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(context, R.drawable.icon));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(addIntent);
}
=======================================
AndroidManifest.xml...
<?xml version="1.0" encoding="utf-8"?>
<manifest
package="com.example.addDeleteShortcut"
android:versionCode="8" android:versionName="1.0.0.1">
<uses-permission
android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission
android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
<supports-screens
android:largeScreens="true"
android:anyDensity="true"
android:smallScreens="true"
android:resizeable="true"
android:normalScreens="true"
/>
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
<activity
android:name=".UIShortcuts"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".shortcutActivity"
android:taskAffinity="com.example.Change"
android:theme="@style/NoBackground"
android:excludeFromRecents="true" >
<intent-filter>
<action android:name="com.example.TOGGLE_SHORTCUT" /
>
<category
android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Hi there,
Did you mange to solve this issue with API 14 or above?
Nixu

Layout will not match_parent

I don't understand why these forums force me to post software development related topics in other forums because I don't have 10 posts yet....no logic in it.
Anyways...
I am trying to add a layout to my main layout at runtime.
The child layout being added is specified in an xml file as follows. My problem is that the layout is not matching the parent in height or width, it is just wrapping content. I don't understand why the match_parent values are being ignored.
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="FORUM WILL NOT LET ME POST URL"
android:id="@+id/midLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
android:layout_weight="1"
android:background="@color/white" >
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a Button" />
</LinearLayout>
Java
Code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
root=(RelativeLayout)findViewById(R.id.main_layout);
root.addView((View) LayoutInflater.from(this).inflate(R.layout.mid_layout,null));
Can anyone provide any clarification as to what is going wrong here?
Anyone?

Android 8.1 : broadcast receive does not work when I restart the smartphone

Hi,
I am designing an android application in java and I would like it to launch when the smartphone starts up I of course registered a BroadcastReceiver for the BOOT event of my phone as explained here but it does not work on Android 10 if not for info it worked on Android 4.1.
Can you help me please ?
Here is my code:
Manifest :
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.openclassrooms.fr.premierprojet">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".PremiereActivite">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".StartAppOnBoot">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
</application>
</manifest>
Classe Main :
Code:
package com.openclassrooms.fr.premierprojet;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class PremiereActivite extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Classe Diffuseur :
Code:
package com.openclassrooms.fr.premierprojet;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class StartAppOnBoot extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent i = new Intent(context, PremiereActivite.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
Cordially.

Scan + Map facilitating in Shipping and Logistics Services

You are probably a shipping and logistics company and your services require you to manage the flow of product delivery. You are trying your best to make sure that the products you handle, are transported from the purpose of origin to destination safely. You are trying to find ways to reinforce your services to cater to your customers better. QR Codes are the need of time as QR Codes store information which is easily scan-able with a smartphone and don't need you to put in any cost-intensive set-QR Codes store information. In fact, a QR Code can store up to 7,089 numeric or 2,953 alphanumeric characters.
Being a Shipping & Logistics Service, you need to keep an eye on goods at various stages during transit for which you do not need to regularly call the fellow operators or track the goods information and delivery status. QR Codes help both shipping and logistics do it easily. Once you place them on the packaging, operators can scan them at various stages of the transit from the warehouse to the delivery destination.
With Scan & Map Kit in your Business App, you can easily keep a track of the delivery packages. From scanning to get information, delivery status, delivery destination, and the directions to guide the Deliveryman to the destination.
Huawei Scan Kit:
HUAWEI Scan Kit scans and parses all major 1D and 2D barcodes and generates QR codes, helping you quickly build barcode scanning functions into your apps. Scan Kit automatically detects, magnifies, and recognizes barcodes from a distance, and is also able to scan a very small barcode in the same way.
Huawei Map Kit:
Huawei Map kit allows can easily integrate map-based functions into your apps and make location-based services work better for you.
Pre-Requisites
1. Integrate HMS Core in project
2. Enable Scan and Map Kit from AGC Console
3. Add agconnet-service.json file in the app level directory
1. Add Dependencies & Permission:
1.1: Add the following dependencies in the app level build.gradle file:
Code:
dependencies {
//Map
implementation 'com.huawei.hms:maps:5.0.3.302'
//Scan
implementation 'com.huawei.hms:scan:1.2.2.300'
}
1.2: Add the following permissions in the AndroidManifest.xml:
Code:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!--Camera permission-->
<uses-permission android:name="android.permission.CAMERA" />
<!--File reading permission-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
2. Add Layout Files:
2.1: Add the activity_main.xml layout file in the layout folder of the res. This is the layout view of the Main Activity of the in the application, contains a Recyclerview to display the arraylist.
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview_parcels"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/_5sdp"
android:stackFromBottom="true" />
</RelativeLayout>
2.2: Add the activity_details.xml layout file in the layout folder of the res. This is the layout view of the Details Activity of the in the application, which contains the Textviews and a Mapview.
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@color/white"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/parcel_details"
android:textStyle="bold"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:gravity="center"
android:textColor="@color/teal_200"
android:textSize="@dimen/_14sdp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/parcelid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="@dimen/_14sdp"/>
<TextView
android:id="@+id/parcelname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="@dimen/_14sdp"/>
<TextView
android:id="@+id/parcelcontact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="@dimen/_14sdp"/>
<TextView
android:id="@+id/parcellocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="@dimen/_14sdp"/>
<TextView
android:id="@+id/parcelstatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/_14sdp"
android:layout_marginBottom="@dimen/_20sdp"/>
<com.huawei.hms.maps.MapView
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraTargetLat="51"
map:cameraTargetLng="10"
map:cameraZoom="8.5"
map:mapType="normal"
map:uiCompass="true"
map:uiZoomControls="true" />
</LinearLayout>
</LinearLayout>
2.3: Add the activity_scan.xml layout file in the layout folder of the res. This is the layout view of the Details Activity of the in the application, which contains the Surfaceview for the camera preview and an ImageView for a customize scanning rectangular area.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:my_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- customize view for camera preview -->
<FrameLayout
android:id="@+id/rim"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C0C0C0">
<SurfaceView
android:id="@+id/surfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<!-- customize scanning rectangle -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:background="#FF000000"
android:alpha="0.1" />
<ImageView
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:background="@drawable/scanningframe" />
</RelativeLayout>
</RelativeLayout>
2.4: Add the cardview_parcel.xml layout file in the layout folder of the res. This is the layout view for the items of Recyclerview in the Main Activity of the application, which contains the Cardview to display Textviews & Imageviews.
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/tools"
android:padding="@dimen/_3sdp">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:orientation="horizontal"
android:background="@color/white"
card_view:cardCornerRadius="5dp"
card_view:cardElevation="4dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linearclick_category"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="@color/white"
android:orientation="horizontal"
android:weightSum="10">
<TextView
android:id="@+id/serial_no"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight="1.5"
android:padding="@dimen/_5sdp"
android:background="@color/purple_200"
android:textColor="@color/black"
android:textSize="@dimen/_11sdp"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="7.5"
android:padding="@dimen/_5sdp"
android:gravity="center"
android:id="@+id/linearmid"
android:orientation="vertical"
android:weightSum="10">
<TextView
android:id="@+id/parcelid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="@color/black" />
<TextView
android:id="@+id/parcelname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black" />
<TextView
android:id="@+id/parcelcontact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black" />
<TextView
android:id="@+id/parcellocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black" />
<TextView
android:id="@+id/parcelstatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end">
<ImageView
android:layout_marginEnd="@dimen/_10sdp"
android:layout_width="@dimen/_20sdp"
android:layout_height="@dimen/_20sdp"
android:scaleType="centerCrop"
android:id="@+id/cameraBtn"
android:visibility="invisible"
android:background="@drawable/ic_camera"/>
<ImageView
android:layout_width="@dimen/_20sdp"
android:layout_height="@dimen/_20sdp"
android:layout_toEndOf="@id/cameraBtn"
android:scaleType="centerCrop"
android:id="@+id/locationBtn"
android:background="@drawable/ic_location"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
3. Add Classes
3.1: Add the MainActivity.java file in the App. This class extends AppCompatActivity and implements the Callback Interface of Parcel Adapter to handle views inside the adapter.
Code:
public class MainActivity extends AppCompatActivity implements ParcelsAdapter.CallbackInterface {
List<ParcelsModal> parcelsModalList;
RecyclerView mRecyclerView;
ParcelsAdapter parcelsAdapter;
public static final int SCAN_START_CODE = 001;
private static final int SCAN_CODE = 002;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
parcelsModalList = new ArrayList<ParcelsModal>();
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview_parcels);
mRecyclerView.setLayoutManager(layoutManager);
// Add Data to list
parcelsModalList.add(new ParcelsModal("00001", "John Atkinson", "123456789", "40.716124, -74.001884","Delivered"));
parcelsModalList.add(new ParcelsModal("00002", "Mark Bennett", "123456789", "40.712188, -73.997378","Delivered"));
parcelsModalList.add(new ParcelsModal("00003", "Jack Brooks", "123456789", "40.717588, -74.010403","Not Delivered"));
parcelsModalList.add(new ParcelsModal("00004", "Alice John", "123456789", "40.715188, -73.995078","Not Delivered"));
parcelsModalList.add(new ParcelsModal("00005", "Julie Berk", "123456789", "40.713588, -74.013303","Not Delivered"));
parcelsAdapter = new ParcelsAdapter(MainActivity.this, (ArrayList<ParcelsModal>) parcelsModalList);
mRecyclerView.setAdapter(parcelsAdapter);
parcelsAdapter.notifyDataSetChanged();
}
//To Handle Callback
@Override
public void onHandleSelection(String text) {
ActivityCompat.requestPermissions(
this,
new String[]{Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE},
SCAN_START_CODE);
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (permissions == null || grantResults == null || grantResults.length < 2 || grantResults[0] != PackageManager.PERMISSION_GRANTED || grantResults[1] != PackageManager.PERMISSION_GRANTED) {
return;
}
if (requestCode == SCAN_START_CODE) {
//start your activity for scanning barcode
Intent newIntent = new Intent(this, ScanActivity.class);
this.startActivityForResult(newIntent, SCAN_CODE);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//receive result after your activity finished scanning
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_OK || data == null) {
return;
}
//Get Code from QR
if (requestCode == SCAN_CODE) {
HmsScan hmsScan = data.getParcelableExtra(ScanActivity.SCAN_RESULT);
if (hmsScan != null && !TextUtils.isEmpty(hmsScan.getOriginalValue())) {
processData(hmsScan.getOriginalValue());
}
}
}
//To Handle Adapter callback data in Activity
private void processData(String value){
for (ParcelsModal modal : parcelsAdapter.getDataAdapterList()) {
//Update date at your Server Here
if(modal.getParcel_id().equals(value)){
modal.setParcel_dilvery_status("Delivered");
Toast.makeText(this, "Parcel Delivered", Toast.LENGTH_SHORT).show();
break; // No need to run the remaining loop
}
}
parcelsAdapter.notifyDataSetChanged();
}
}
How many types of barcode can Huawei Scan kit generates ?

Categories

Resources