https://drive.google.com/file/d/0B2ag35s4X53Eb2pSQVI1SzNudE0/view
Samay Software Android 2018
Tuesday, March 19, 2019
Wednesday, January 2, 2019
Sensors
Sensors Overview The Android platform supports three broad categories of sensors: •Motion sensors These sensors measure acceleration forces and rotational forces along three axes. This category includes accelerometers, gravity sensors, gyroscopes, and rotational vector sensors. •Environmental sensors These sensors measure various environmental parameters, such as ambient air temperature and pressure, illumination, and humidity. This category includes barometers, photometers, and thermometers. •Position sensors These sensors measure the physical position of a device. This category includes orientation sensors and magnetometers. You can access sensors available on the device and acquire raw sensor data by using the Android sensor framework. What can we do? • Determine which sensors are available on a device. • Determine an individual sensor's capabilities, such as its maximum range, manufacturer, power requirements, and resolution. • Acquire raw sensor data and define the minimum rate at which you acquire sensor data. • Register and unregister sensor event listeners that monitor sensor changes. Some sensors are hardware based and some are software based. Hardware based are typically the physical components built into the handset. Software based sensors derive their information from one or more hardware based sensors and so they mimic the hardware based sensors and seem to be similar. So they are also called as virtual/synthetic sensors. Package? android.hardware package // => to get Sensor Manager SensorManager sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE); // => To get List of all sensors List<Sensor> lstSensors = sm.getSensorList(Sensor.TYPE_ALL); // => To find a particular sensor if (sm.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) != null){ // Success! There's a magnetometer. } else { // Failure! No magnetometer. } // => To use a particular sensor, call public methods like: s.getResolution(), s.getMaximumRange(), s.getPower()
Code
package net.samaysoftware.bletest; import android.graphics.Color; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Gravity; import android.widget.LinearLayout; import android.widget.TextView; import java.util.Date; import java.util.List; public class SensorActivity extends AppCompatActivity implements SensorEventListener { TextView tvSensorActivity; LinearLayout llsensor; SensorManager sm; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sensor); tvSensorActivity = (TextView) findViewById(R.id.tvsensor1); llsensor = (LinearLayout) findViewById(R.id.llSensor); sm = (SensorManager) getSystemService(this.SENSOR_SERVICE); Sensor s = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); sm.registerListener(this,s,SensorManager.SENSOR_DELAY_NORMAL); llsensor.setBackgroundColor(Color.parseColor("#ffffff")); } long lasttime; @Override public void onSensorChanged(SensorEvent sensorEvent) { float[] arr = sensorEvent.values; long currenttime = new Date().getTime(); if(currenttime - lasttime >200){ float ans = (arr[0]*arr[0]+arr[1]*arr[1]+arr[2]*arr[2])/ (SensorManager.GRAVITY_EARTH*SensorManager.GRAVITY_EARTH); if(ans>3){ llsensor.setBackgroundColor(Color.parseColor("#ff0000")); } else{ llsensor.setBackgroundColor(Color.parseColor("#ffffff")); } lasttime = currenttime; } } @Override public void onAccuracyChanged(Sensor sensor, int i) { } @Override protected void onDestroy() { super.onDestroy(); sm.unregisterListener(this); } } /*List<Sensor> sensorList = sm.getSensorList(Sensor.TYPE_ALL); for (Sensor s: sensorList ) { tvSensorActivity.append(s.getName()+"\n"); }*//* if(arr[0]==1){ llsensor.setBackgroundColor(Color.parseColor("#ffffff")); }else{ // object detected llsensor.setBackgroundColor(Color.parseColor("#ff0000")); }*/ /*//tvSensorActivity.setText("X="+arr[0]+"\n"+"Y="+arr[1]+"\n"+"Z="+arr[2]); float y = arr[1]; if(y<2 && y>-2){ llsensor.setBackgroundColor(Color.parseColor("#ffffff")); } else if(y<4 && y>=2){ llsensor.setBackgroundColor(Color.parseColor("#ffaaaa")); } else if(y<6 && y>=4){ llsensor.setBackgroundColor(Color.parseColor("#ff7777")); } else if(y<8 && y>=6){ llsensor.setBackgroundColor(Color.parseColor("#ff4444")); } else if(y<10 && y>=8){ llsensor.setBackgroundColor(Color.parseColor("#ff0000")); } else if(y>-4 && y<=-2){ llsensor.setBackgroundColor(Color.parseColor("#aaffaa")); } else if(y>-6 && y<=-4){ llsensor.setBackgroundColor(Color.parseColor("#77ff77")); } else if(y>-8 && y<=-6){ llsensor.setBackgroundColor(Color.parseColor("#44ff44")); } else if(y>-10 && y<=-8){ llsensor.setBackgroundColor(Color.parseColor("#00ff00")); }*/
Tuesday, January 1, 2019
GPS (Location Services) and Vibrator
This code shows GPSDemoActivity with GPS latitude,
longitude, geocoding into address,
sharing location as text, showing location on google maps
and vibration effect on button click.
Layout File: https://drive.google.com/file/d/1fFkpk2isKM9L5sxRI-6h6_BqrJrumEAQ/view?usp=sharing
Java File: https://drive.google.com/file/d/1NgrzgDehmvjCsIP7hRirbMV9PLN8Apf1/view?usp=sharing
Another Java File: https://drive.google.com/file/d/1ZCVdgb9JQSKrJ-BQ1Hjd9BF7rZUBUm8T/view?usp=sharing
Manifest: Please declare Access Fine Location, Access Coarse Location, Internet and Vibration permissions.
Images: 2 icon images are used in layout file which should be present in drawable folder.
Friday, October 12, 2018
Registration, Login and Category List with DOTNET MVC
Register Activity
package net.samaysoftware.listviewdemo; import android.content.Intent; import android.os.AsyncTask; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import utility.HttpManager; import utility.RequestPackage; public class RegisterActivity extends AppCompatActivity implements View.OnClickListener { EditText etName, etMobile, etEmail, etUsername, etPassword, etAddress, etCity; Button btnRegister; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_register); findAllViews(); btnRegister.setOnClickListener(this); } private void findAllViews() { etName = (EditText)findViewById(R.id.etCName); etEmail = (EditText)findViewById(R.id.etCEmail); etMobile = (EditText)findViewById(R.id.etCMobile); etUsername = (EditText)findViewById(R.id.etCUsername); etPassword = (EditText)findViewById(R.id.etCPassword); etAddress = (EditText)findViewById(R.id.etCAddress); etCity = (EditText)findViewById(R.id.etCCity); btnRegister = (Button) findViewById(R.id.btnRegister); } @Override public void onClick(View view) { new MyTask().execute(); } class MyTask extends AsyncTask<String, String, String>{ String name, email, mobile, address, city, username, password; @Override protected void onPreExecute() { super.onPreExecute(); name = etName.getText().toString(); email = etEmail.getText().toString(); mobile = etMobile.getText().toString(); address = etAddress.getText().toString(); city = etCity.getText().toString(); username = etUsername.getText().toString(); password = etPassword.getText().toString(); } @Override protected String doInBackground(String... strings) { RequestPackage rp = new RequestPackage(); rp.setMethod("GET"); rp.setUri("http://192.168.31.163:49962/MobileApp/SignUp"); rp.setParam("Cname",name); rp.setParam("Email",email); rp.setParam("Mobile",mobile); rp.setParam("Username",username); rp.setParam("Password",password); rp.setParam("City",city); rp.setParam("Address",address); String ans = HttpManager.getData(rp); return ans.trim(); } @Override protected void onPostExecute(String s) { super.onPostExecute(s); if(s.equals("success")){ Toast.makeText(RegisterActivity.this, "Registration is successful !!", Toast.LENGTH_LONG).show(); Intent i = new Intent(RegisterActivity.this, LoginActivityDemo.class); startActivity(i); finish(); } else{ Toast.makeText(RegisterActivity.this, "There seems to be some problem, please try again later !!", Toast.LENGTH_LONG).show(); } } } }
LoginActivity
package net.samaysoftware.listviewdemo; import android.app.ProgressDialog; import android.content.Intent; import android.content.SharedPreferences; import android.os.AsyncTask; import android.preference.PreferenceManager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import utility.HttpManager; import utility.RequestPackage; public class LoginActivityDemo extends AppCompatActivity implements View.OnClickListener { String un, pw; EditText etUser, etPass; Button btnLogin; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login_demo); etUser = (EditText) findViewById(R.id.etUser); etPass = (EditText) findViewById(R.id.etPass); btnLogin = (Button) findViewById(R.id.btnMyLogin); btnLogin.setOnClickListener(this); /* SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(LoginActivityDemo.this); int oldid = sp.getInt("id", -1000); if(oldid!=-1000){ Intent i = new Intent(LoginActivityDemo.this, CategoryListActivity.class); startActivity(i); finish(); }*/ } @Override public void onClick(View view) { new LoginTask().execute(); } class LoginTask extends AsyncTask<String, String, String>{ ProgressDialog pd; String un, pw; @Override protected void onPreExecute() { super.onPreExecute(); un = etUser.getText().toString(); pw = etPass.getText().toString(); pd = new ProgressDialog(LoginActivityDemo.this); pd.setTitle("Please Wait"); pd.setMessage("Loading"); pd.setIndeterminate(true); pd.setCancelable(false); pd.show(); } @Override protected String doInBackground(String... arr) { RequestPackage rp = new RequestPackage(); rp.setMethod("GET"); rp.setUri("http://192.168.31.163:49962/MobileApp/SignIn"); rp.setParam("Username", un); rp.setParam("Password", pw); String ans = HttpManager.getData(rp); return ans.trim(); } @Override protected void onPostExecute(String ans) { super.onPostExecute(ans); if(pd!=null){ pd.dismiss(); } /* int id; try { id = Integer.parseInt(ans); }catch (Exception ee){ Toast.makeText(LoginActivityDemo.this, "Cannot connect to server", Toast.LENGTH_LONG).show(); return; } if(id==0){ Toast.makeText(LoginActivityDemo.this, "Invalid username or password !!", Toast.LENGTH_LONG).show(); return; } SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(LoginActivityDemo.this); sp.edit().putInt("id", id).apply();*/ if(ans.equals("success")) { Intent i = new Intent(LoginActivityDemo.this, CategoryListActivity.class); startActivity(i); finish(); } else{ Toast.makeText(LoginActivityDemo.this, "Invalid username or password !!", Toast.LENGTH_LONG).show(); } } } }CATEGORY LIST
package net.samaysoftware.listviewdemo; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.AsyncTask; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.*; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import utility.HttpManager; import utility.RequestPackage; public class CategoryListActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { ListView listView; ArrayList<String> arrlist = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_country_list); listView = (ListView) findViewById(R.id.lvDynamicCountries); new MyTask().execute(); } @Override public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) { String catname = arrlist.get(pos); Intent i = new Intent(this, ProductListActivity.class); i.putExtra("catname", catname); startActivity(i); /* AlertDialog.Builder builder1 = new AlertDialog.Builder(this); builder1.setMessage("Are you sure you want to delete"); builder1.setCancelable(true); builder1.setPositiveButton( "Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder1.setNegativeButton( "No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert11 = builder1.create(); alert11.show();*/ /* AlertDialog.Builder builderSingle = new AlertDialog.Builder(this); builderSingle.setIcon(R.drawable.flagindia); builderSingle.setTitle("Select One Name:"); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.select_dialog_singlechoice); arrayAdapter.add("Hardik"); arrayAdapter.add("Archit"); arrayAdapter.add("Jignesh"); arrayAdapter.add("Umang"); arrayAdapter.add("Gatti"); builderSingle.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String strName = arrayAdapter.getItem(which); AlertDialog.Builder builderInner = new AlertDialog.Builder(CategoryListActivity.this); builderInner.setMessage(strName); builderInner.setTitle("Your Selected Item is"); builderInner.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog,int which) { dialog.dismiss(); } }); builderInner.show(); } }); builderSingle.show(); */ } class MyTask extends AsyncTask<String, String, String>{ ProgressDialog pd = null; @Override protected String doInBackground(String... strings) { RequestPackage rp = new RequestPackage(); rp.setMethod("GET"); rp.setUri("http://192.168.31.163:49962/MobileApp/GetAllCategories"); String ans = HttpManager.getData(rp); return ans.trim(); } @Override protected void onPreExecute() { super.onPreExecute(); pd = new ProgressDialog(CategoryListActivity.this); pd.setIndeterminate(true); pd.setMessage("Loading...."); pd.setCancelable(false); pd.setTitle("Please Wait"); pd.show(); } @Override protected void onPostExecute(String ans) { super.onPostExecute(ans); //arr = ans.split(","); JSONArray arr = null; try { arr = new JSONArray(ans); for(int i = 0; i < arr.length(); i++){ JSONObject obj = arr.getJSONObject(i); String catname = obj.getString("CatName"); arrlist.add(catname); } } catch (JSONException e) { e.printStackTrace(); } ArrayAdapter<String> aa = new ArrayAdapter<>(CategoryListActivity.this, android.R.layout.simple_list_item_1, android.R.id.text1, arrlist); listView.setAdapter(aa); listView.setOnItemClickListener(CategoryListActivity.this); pd.dismiss(); } } }
Friday, September 28, 2018
Sqlite Database insert
package net.samaysoftware.listviewdemo; import android.content.Intent; import android.database.sqlite.SQLiteDatabase; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import java.io.FileReader; import java.io.Reader; public class NewExpenseActivity extends AppCompatActivity implements View.OnClickListener { EditText etReason, etAmount; Button btnAddExpense; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_new_expense); setTitle("Add expense"); createTable(); etReason = (EditText) findViewById(R.id.etReason); etAmount = (EditText) findViewById(R.id.etAmount); btnAddExpense = (Button) findViewById(R.id.btnAddExpense); btnAddExpense.setOnClickListener(this); } private void createTable() { SQLiteDatabase db = null; try { db = openOrCreateDatabase("SampleDB", MODE_PRIVATE,null); String q = "create table if not exists Expense(expenseid integer primary key autoincrement,reason varchar(100), amount integer)"; db.execSQL(q); }catch (Exception ee){ Toast.makeText(this, "Some error while creating expense table", Toast.LENGTH_LONG).show(); } finally { if(db!=null && db.isOpen()) { db.close(); } } } @Override public void onClick(View view) { String stramount = etAmount.getText().toString(); String strreason = etReason.getText().toString(); SQLiteDatabase db = null; try { db = openOrCreateDatabase("SampleDB", MODE_PRIVATE,null); String q = "insert into Expense(amount, reason) values("+stramount+",'"+strreason+"')"; db.execSQL(q); Toast.makeText(this, "Expense added successfully !!", Toast.LENGTH_LONG).show(); Intent i = new Intent(this, ExpenseListActivity.class); startActivity(i); }catch (Exception ee){ Toast.makeText(this, "Some error while inserting in Expense table", Toast.LENGTH_LONG).show(); } finally { if(db!=null && db.isOpen()) { db.close(); } } } }
Thursday, September 27, 2018
Android Code with below PHP Code for Login, CategoryList, and ProductList Display with Alert Dialog code
LOGIN
package net.samaysoftware.listviewdemo; import android.app.ProgressDialog; import android.content.Intent; import android.content.SharedPreferences; import android.os.AsyncTask; import android.preference.PreferenceManager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import utility.HttpManager; import utility.RequestPackage; public class LoginActivityDemo extends AppCompatActivity implements View.OnClickListener { String un, pw; EditText etUser, etPass; Button btnLogin; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login_demo); etUser = (EditText) findViewById(R.id.etUser); etPass = (EditText) findViewById(R.id.etPass); btnLogin = (Button) findViewById(R.id.btnMyLogin); btnLogin.setOnClickListener(this); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(LoginActivityDemo.this); int oldid = sp.getInt("id", -1000); if(oldid!=-1000){ Intent i = new Intent(LoginActivityDemo.this, CategoryListActivity.class); startActivity(i); finish(); } } @Override public void onClick(View view) { new LoginTask().execute(); } class LoginTask extends AsyncTask<String, String, String>{ ProgressDialog pd; String un, pw; @Override protected void onPreExecute() { super.onPreExecute(); un = etUser.getText().toString(); pw = etPass.getText().toString(); pd = new ProgressDialog(LoginActivityDemo.this); pd.setTitle("Please Wait"); pd.setMessage("Loading"); pd.setIndeterminate(true); pd.setCancelable(false); pd.show(); } @Override protected String doInBackground(String... arr) { RequestPackage rp = new RequestPackage(); rp.setMethod("GET"); rp.setUri("http://192.168.31.10:81/2018testing/mobilesupport.php"); rp.setParam("type","login"); rp.setParam("un", un); rp.setParam("pw", pw); String ans = HttpManager.getData(rp); return ans.trim(); } @Override protected void onPostExecute(String ans) { super.onPostExecute(ans); if(pd!=null){ pd.dismiss(); } int id; try { id = Integer.parseInt(ans); }catch (Exception ee){ Toast.makeText(LoginActivityDemo.this, "Cannot connect to server", Toast.LENGTH_LONG).show(); return; } if(id==0){ Toast.makeText(LoginActivityDemo.this, "Invalid username or password !!", Toast.LENGTH_LONG).show(); return; } SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(LoginActivityDemo.this); sp.edit().putInt("id", id).apply(); Intent i = new Intent(LoginActivityDemo.this, CategoryListActivity.class); startActivity(i); finish(); } } }
CATEGORY LIST
package net.samaysoftware.listviewdemo; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.AsyncTask; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.*; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import utility.HttpManager; import utility.RequestPackage; public class CategoryListActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { ListView listView; String[] arr; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_country_list); listView = (ListView) findViewById(R.id.lvDynamicCountries); new MyTask().execute(); } @Override public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) { String catname = arr[pos]; Intent i = new Intent(this, ProductListActivity.class); i.putExtra("catname", catname); startActivity(i); /* AlertDialog.Builder builder1 = new AlertDialog.Builder(this); builder1.setMessage("Are you sure you want to delete"); builder1.setCancelable(true); builder1.setPositiveButton( "Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder1.setNegativeButton( "No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert11 = builder1.create(); alert11.show();*/ /* AlertDialog.Builder builderSingle = new AlertDialog.Builder(this); builderSingle.setIcon(R.drawable.flagindia); builderSingle.setTitle("Select One Name:"); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.select_dialog_singlechoice); arrayAdapter.add("Hardik"); arrayAdapter.add("Archit"); arrayAdapter.add("Jignesh"); arrayAdapter.add("Umang"); arrayAdapter.add("Gatti"); builderSingle.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String strName = arrayAdapter.getItem(which); AlertDialog.Builder builderInner = new AlertDialog.Builder(CategoryListActivity.this); builderInner.setMessage(strName); builderInner.setTitle("Your Selected Item is"); builderInner.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog,int which) { dialog.dismiss(); } }); builderInner.show(); } }); builderSingle.show(); */ } class MyTask extends AsyncTask<String, String, String>{ ProgressDialog pd = null; @Override protected String doInBackground(String... strings) { RequestPackage rp = new RequestPackage(); rp.setMethod("GET"); rp.setUri("http://192.168.31.10:81/2018testing/mobilesupport.php"); rp.setParam("type","getcategorylist"); String ans = HttpManager.getData(rp); return ans.trim(); } @Override protected void onPreExecute() { super.onPreExecute(); pd = new ProgressDialog(CategoryListActivity.this); pd.setIndeterminate(true); pd.setMessage("Loading...."); pd.setCancelable(false); pd.setTitle("Please Wait"); pd.show(); } @Override protected void onPostExecute(String ans) { super.onPostExecute(ans); arr = ans.split(","); ArrayAdapter<String> aa = new ArrayAdapter<>(CategoryListActivity.this, android.R.layout.simple_list_item_1, android.R.id.text1, arr); listView.setAdapter(aa); listView.setOnItemClickListener(CategoryListActivity.this); pd.dismiss(); } } }PRODUCT LIST
package net.samaysoftware.listviewdemo; import android.app.ProgressDialog; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import utility.HttpManager; import utility.RequestPackage; public class ProductListActivity extends AppCompatActivity{ ListView listView; String[] arr; String catname; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); catname = getIntent().getStringExtra("catname"); setContentView(R.layout.activity_country_list); listView = (ListView) findViewById(R.id.lvDynamicCountries); new MyTask().execute(); } class MyTask extends AsyncTask<String, String, String>{ ProgressDialog pd = null; @Override protected String doInBackground(String... strings) { RequestPackage rp = new RequestPackage(); rp.setMethod("GET"); rp.setUri("http://192.168.31.10:81/2018testing/mobilesupport.php"); rp.setParam("type","getproductlist"); rp.setParam("catname",catname); String ans = HttpManager.getData(rp); return ans.trim(); } @Override protected void onPreExecute() { super.onPreExecute(); pd = new ProgressDialog(ProductListActivity.this); pd.setIndeterminate(true); pd.setMessage("Loading...."); pd.setCancelable(false); pd.setTitle("Please Wait"); pd.show(); } @Override protected void onPostExecute(String ans) { super.onPostExecute(ans); arr = ans.split(","); ArrayAdapter<String> aa = new ArrayAdapter<String>(ProductListActivity.this, android.R.layout.simple_list_item_1, android.R.id.text1, arr); listView.setAdapter(aa); pd.dismiss(); } } }
Thursday, September 20, 2018
PHP Code for MobileSupport.php
<?php
$type = $_REQUEST["type"];
if($type=="login"){
$username= $_REQUEST["un"];
$pw= $_REQUEST["pw"];
if($username=="v" && $pw=="v"){
echo "4";
}
else{
echo "0";
}
}
else if($type=="getcategorylist"){
echo "Clothes,Electronics,Food";
}
else if($type=="getproductlist"){
$catname = $_REQUEST["catname"];
if($catname == "Clothes"){
echo "Tshirt,Jeans,Shirt";
}
if($catname == "Electronics"){
echo "TV,Mobile,Laptop";
}
if($catname == "Food"){
echo "Burger,Pizza,Noodles";
}
}
else if($type=="getmyprofile"){
}
else if($type=="getproductdetails"){
}
?>
$type = $_REQUEST["type"];
if($type=="login"){
$username= $_REQUEST["un"];
$pw= $_REQUEST["pw"];
if($username=="v" && $pw=="v"){
echo "4";
}
else{
echo "0";
}
}
else if($type=="getcategorylist"){
echo "Clothes,Electronics,Food";
}
else if($type=="getproductlist"){
$catname = $_REQUEST["catname"];
if($catname == "Clothes"){
echo "Tshirt,Jeans,Shirt";
}
if($catname == "Electronics"){
echo "TV,Mobile,Laptop";
}
if($catname == "Food"){
echo "Burger,Pizza,Noodles";
}
}
else if($type=="getmyprofile"){
}
else if($type=="getproductdetails"){
}
?>
Subscribe to:
Posts (Atom)
Near by App
https://drive.google.com/file/d/0B2ag35s4X53Eb2pSQVI1SzNudE0/view
-
package net.samaysoftware.listviewdemo; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.*...
-
Sensors Overview The Android platform supports three broad categories of sensors: • Motion sensors These sensors measure acceleration forc...
-
This code shows GPSDemoActivity with GPS latitude, longitude, geocoding into address, sharing location as text, showing location on googl...