Skip to main content

Posts

TabLayout in Android

Create Tab Layout Like Whatsapp Tab We need to Create Fragment Depend on Tab Create For Example if we need three tab then we require three fragment public class MainActivity extends AppCompatActivity { TabLayout tabLayout ; ViewPager viewPager ; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout. activity_main ); tabLayout = findViewById(R.id. tablayout ); viewPager = findViewById(R.id. pager ); ViewpageAdapter viewpageAdapter = new ViewpageAdapter(getSupportFragmentManager()); viewpageAdapter.addFragment( new Tab1(), "Chat" ); viewpageAdapter.addFragment( new Tab2(), "Status" ); viewpageAdapter.addFragment( new Tab3(), "Call" ); tabLayout .getTabAt( 0 ).setIcon(R.drawable. thumblike ); viewPager .setAdapter(viewpageAdapter); tabLayout .setupWithViewPager( viewPager ); } } publi...

JsonParsing Using AsyncTask in Android

 Create One ServiceHandler Class for Manage Connection For JsonParsing ServiceHandler.java public class ServiceHandler { public String getstring(String url) { StringBuilder sb= new StringBuilder(); String result; try { URL url1= new URL(url); HttpURLConnection con= (HttpURLConnection) url1.openConnection(); InputStream in= new BufferedInputStream(con.getInputStream()); BufferedReader br= new BufferedReader( new InputStreamReader(in)); String line; while ((line=br.readLine())!= null ) { sb.append(line+ " \n " ); } } catch (Exception e) { } result=sb.toString(); return result; } } public class MainActivity extends AppCompatActivity { ListView lv ; String URLDATA = "Enter URL" ; String CONTACT = "contacts" ; String ID = "id" ; String NAME...

Upload Image and PDF file on Server with Android and PHP Using Retrofit

PHP File <?php  $con=new MySQLi("localhost","","","");  if($_SERVER['REQUEST_METHOD']=='POST'){     $image = $_POST['img'];     $name = $_POST['name'];     $sql ="SELECT * from img";     $res = mysqli_query($con,$sql);     $id = 0;     while($row = mysqli_fetch_array($res)){             $id = $row['id'];     }     $path = "upload/$id.pdf";     $actualpath = "URL/$path";     $sql = "INSERT INTO img (img,name) VALUES ('$actualpath','$name')";     if(mysqli_query($con,$sql)){         file_put_contents($path,base64_decode($image));         echo "Successfully Uploaded";     }     mysqli_close($con); }else{     echo "Error"; } public interface ApiConfig { @Multipart @POST( "uploadpdf.php" ) Call<ServerRespons...

Network Security Exception in Android Retrofit Cleartext HTTP traffic not permitted

Create One directory in res/xml Create file in xml directory Past give below code : < network-security-config > < base-config cleartextTrafficPermitted= "true" /> < domain-config > < domain includeSubdomains= "true" >www.xyz.com</ domain >> < trust-anchors > < certificates src= "system" /> </ trust-anchors > </ domain-config > </ network-security-config > Add one Line into AndroidMenifest.xm File in application tag : android :networkSecurityConfig= "@xml/yourfilename" android :usesCleartextTraffic= "true"