Friday 31 January 2020

How to implement Facebook audience network banner ad in android app using Android Studio

Its very simple to implement Facebook audience network banner ad in android app using Android Studio. We will complete it in 4 Steps.

1. Creating Android Studio Project and adding Facebook Audience network dependency in the project
2. Adding layout for banner add in layout xml file
3. Initializing Facebook Audience network SDK and finally showing banner ad
4. Adding internet permission in Manifest file

1. Creating Android Studio Project and adding Facebook Audience network dependency in the project

Create an android studio project for creating an android app and wait for project build completion.
Now open build.gradle (App level) file and add the following dependency between dependencies section.
(At the time of writing this article this is the latest version)
implementation 'com.facebook.android:audience-network-sdk:5.6.1'

2. Adding layout for banner add in layout xml file

To show banner ad in our application, it needs any container which can hold the banner ad. So here we are using LinearLayout as a container. and we are giving its id as bannerAdContainerLinearLayout.

<LinearLayout  
   android:layout_width="match_parent" 
   android:orientation="vertical"    
   android:layout_alignParentBottom="true"    
   android:id="@+id/bannerAdContainerLinearLayout" 
   android:layout_height="wrap_content">
</LinearLayout>

3. Initializing Facebook Audience network SDK and finally showing banner ad

To show ads using Facebook Audience network in our application it is necessary that it should be initialized correctly. To initialize the Facebook Audience network SDK write the below code into your MainActivity.java OnCreate method.

AudienceNetworkAds.initialize(this);

//below statements are optional and will be used when you are testing your app and its not in release
//for testing only
AdSettings.setTestAdType(AdSettings.TestAdType.IMG_16_9_APP_INSTALL);
//for testing only
AdSettings.getTestAdType();
//for testing only
dSettings.addTestDevice("Device hash id");
Now we initialized the SDK, its time to load banner ad and show the ad
// creating adView object with our placement ID
AdView adView = new AdView(this, "IMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID", AdSize.BANNER_HEIGHT_50);
// finding linear layout container for banner which we have defined in our layout file
LinearLayout bannerAdContainer = findViewById(R.id.bannerAdContainerLinearLayout);
//adding adView to container
bannerAdContainer.addView(adView);
// loading our ad into adview and showing it to the user
adView.loadAd();

4. Adding internet permission in Manifest file

We will be able to show any ad to the user if our app has internet access permission.
So we have it add this permission into out AndroidManifest.xml file.
Add this line between <manifest> starting and closing tag
<uses-permission android:name="android.permission.INTERNET"/>




Now launch the application and we will see a test banner ad from facebook


















Thursday 7 February 2019

WhatsApp will give Rs 1.8 crores to new Indian startups, Here is all you need to know

The "Startup India WhatsApp Grand Challenge" has been appraise growth in the entrepreneurial sector. Total prize money of Rs 1.8 crore is up for grabs.

Key Points:

  • The competition carries a total prize amount of Rs 1.8 crore for top 5 winners.
  • The competition invites ideas in various sectors such as healthcare, rural, economy, financial and more.
  • Registrations for the contest will be opened till March 10, 2019.
  • Over the last few years, WhatsApp has come across as more than just a messenger in India. The platform has been responsible for providing a local social network in the form of WhatsApp groups. 
  • The app has also been a platform to several growing businesses as well as help fuel new startups. To help with that, the company launched WhatsApp for Business that offered more business tools to aid startups as well as entrepreneurs. Now, the company has come with content that will help boost the entrepreneurial sector in India.
  • WhatsApp has launched the "Startup India WhatsApp Grand Challenge" in India. The contest has been organized to fuel growth in India's startup as well as the entrepreneurial sector. 
  • The competition carries a total prize amount of Rs 1.8 crore for top 5 winners.
  • The competition is open to all entrepreneurs and invites ideas in various sectors such as healthcare, rural, economy, financial and digital inclusion, education and citizen safety.
"Entrepreneurs with highly innovative ideas, business models that solve for a local India problem, making a large scale socio-economic impact, are invited to apply," WhatsApp said in a media release.
Registrations for the contest will be opened till March 10, 2019. 
The process for the selection has been listed below:
  1. The applications will be evaluated by an independent evaluation committee.
  2. Out of the selected ones, the 30 best ideas will be shortlisted for the subsequent round and on to 10 in the following round.
  3. The final 10 selected ideas will be invited to participate in the final round of the grand finale.
  4. At the end, the five winning ideas will receive a monetary prize of $50,000 (approximately Rs 35.6 lakhs) on May 24.
According to data provided by WhatsApp, the messenger platform has been known to help around 84 per cent of small and mid-tier businesses communicate in their field. Additionally, around 80 per cent of such businesses have found WhatsApp to help them grow.

 

Wednesday 6 February 2019

WhatsApp struggles to protect us from fake news

The government has taken note of reports about spread of fake news, misinformation or disinformation on the Internet, Union Minister of State for Home Hansraj Ahir said.


New Delhi:

  • In the wake of the spread of fake news, the centre has directed the messaging platform WhatsApp to come out with effective solutions that can bring in accountability and facilitate enforcement of law against dissemination of wrong information.
  • Union Minister of State for Home Hansraj Ahir said in Lok Sabha that the government has taken note of reports about spread of fake news, misinformation or disinformation on the Internet, particularly using WhatsApp platform.
  • "Ministry of Electronics and Information Technology issued notices to WhatsApp conveying that they need to come out with effective solutions that can bring in accountability and facilitate enforcement of law in addition to labelling forwards and weeding out fake news," he said in a written reply to a question.
  • Mr Ahir said WhatsApp has conveyed that a number of steps have been taken by it to address the issue of fake news propagated using the platform.

COMMENT
"Meetings with law enforcement agencies and intermediaries are held on regular basis to strengthen the coordination framework for better enforcement of the law," he said.

 

Saturday 15 December 2018

Auto check for update function for android app | android studio

If you are having an app on Google Play Store and you want that whenever you update the app on playstore and when the user opens the older version of app he/she will get a dialog that there is an Update available .
Each time the user will open the app he/she will get the same dialog until he/she updates the app.

Advantages:

This will inform the user as a notice that there is an update.

Users will have the latest version of app.
Automatically checks for update in the background.
There is also an option for mannual check and automatic check.




How to use:

Step-I
I have already create a class(AppUpdateChecker.java) to achieve this feature that will handle it automatically.

AppUpdateChecker.java
 
 package com.programmingdesire;  
 import android.app.Activity;  
 import android.app.ProgressDialog;  
 import android.content.DialogInterface;  
 import android.content.Intent;  
 import android.content.pm.PackageInfo;  
 import android.content.pm.PackageManager;  
 import android.net.Uri;  
 import android.os.AsyncTask;  
 import android.support.v7.app.AlertDialog;  
 import android.widget.Toast;  
 import org.jsoup.Jsoup;  
 public class AppUpdateChecker {  
   private Activity activity;  
   public AppUpdateChecker(Activity activity) {  
     this.activity = activity;  
   }  
   //current version of app installed in the device  
   private String getCurrentVersion(){  
     PackageManager pm = activity.getPackageManager();  
     PackageInfo pInfo = null;  
     try {  
       pInfo = pm.getPackageInfo(activity.getPackageName(),0);  
     } catch (PackageManager.NameNotFoundException e1) {  
       e1.printStackTrace();  
     }  
     return pInfo.versionName;  
   }  
   private class GetLatestVersion extends AsyncTask<String, String, String> {  
     private String latestVersion;  
     private ProgressDialog progressDialog;  
     private boolean manualCheck;  
     GetLatestVersion(boolean manualCheck) {  
       this.manualCheck = manualCheck;  
     }  
     @Override  
     protected void onPostExecute(String s) {  
       super.onPostExecute(s);  
       if (manualCheck)  
       {  
         if (progressDialog!=null)  
         {  
           if (progressDialog.isShowing())  
           {  
             progressDialog.dismiss();  
           }  
         }  
       }  
       String currentVersion = getCurrentVersion();  
       //If the versions are not the same  
       if(!currentVersion.equals(latestVersion)&&latestVersion!=null){  
         final AlertDialog.Builder builder = new AlertDialog.Builder(activity);  
         builder.setTitle("An Update is Available");  
         builder.setMessage("Its better to update now");  
         builder.setPositiveButton("Update", new DialogInterface.OnClickListener() {  
           @Override  
           public void onClick(DialogInterface dialog, int which) {  
             //Click button action  
             activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+activity.getPackageName())));  
             dialog.dismiss();  
           }  
         });  
         builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {  
           @Override  
           public void onClick(DialogInterface dialog, int which) {  
             //Cancel button action  
           }  
         });  
         builder.setCancelable(false);  
         builder.show();  
       }else {  
         if (manualCheck) {  
           Toast.makeText(activity, "No Update Available", Toast.LENGTH_SHORT).show();  
         }  
       }  
     }  
     @Override  
     protected void onPreExecute() {  
       super.onPreExecute();  
       if (manualCheck) {  
         progressDialog=new ProgressDialog(activity);  
         progressDialog.setMessage("Checking For Update.....");  
         progressDialog.setCancelable(false);  
         progressDialog.show();  
       }  
     }  
     @Override  
     protected String doInBackground(String... params) {  
       try {  
         //It retrieves the latest version by scraping the content of current version from play store at runtime  
         latestVersion = Jsoup.connect("https://play.google.com/store/apps/details?id=" + activity.getPackageName() + "&hl=it")  
             .timeout(30000)  
             .userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")  
             .referrer("http://www.google.com")  
             .get()  
             .select(".hAyfc .htlgb")  
             .get(7)  
             .ownText();  
         return latestVersion;  
       } catch (Exception e) {  
         return latestVersion;  
       }  
     }  
   }  
   public void checkForUpdate(boolean manualCheck)  
   {  
     new GetLatestVersion(manualCheck).execute();  
   }  
 }  

Step-II
Add a library to your build.gradle(App level) file.

   implementation 'org.jsoup:jsoup:1.10.2'  

Step-III
The last step is to copy that class and then write two lines of code.


 AppUpdateChecker appUpdateChecker=new AppUpdateChecker(this);  //pass the activity in constructure
 appUpdateChecker.checkForUpdate(false); //mannual check false here

Lets understand what is manual check

If manual check is true then
Manual check will be on a button click this will show the dialog as "Checking for update"



If manual  check is false then
Checking for update will be performed in the background and finally a dialog will be visible if there is any update.


If user will click on update it will open your app in playstore to update your app.

Thats all.

Thanks for visiting, I will come with new code snippet.
Happy Coding.......





Save Your Friends Status - WhatsApp Status Saver App

Love your friend's status ? Hesitate to ask? you are on the right page.

Its been easy to grab the whatsapp status of your whatsapp contacts.

So here are the steps to save or share the status (Image or Video) of whatsApp.

1. Install  WhatsApp Status Saver App by ProgrammingDesire.com in your phone.


2. Open whatsApp and watch some status.

3.Come back to Status Saver and you will find the status there to download and share.



Directly open whatsapp from status saver . 


You can save status to your internal storage. 


You can directly share the status to whatsApp or any other social medial very easily by clicking on the share button. 

Now Enjoy the life with pride.









Sunday 9 December 2018

How to insert images in C/ C++ using graphics(100% working)

Hello friends today we will learn how to insert images in  C++ language very easily using graphics. The things that are required for this work are listed here .....

1.Code blocks compiler installed on your system:

Code::Blocks is a freeopen-source cross-platform IDE that supports multiple compilers including GCCClang and Visual C++. It is developed in C++ using wxWidgets as the GUI toolkit. Using a plugin architecture, its capabilities and features are defined by the provided plugins. Currently, Code::Blocks is oriented towards CC++, and Fortran. It has a custom build system and optional Make support.(by wikipedia).

2.Graphics libraries should set up with code blocks:

When we install code blocks then there is no library and header file of graphics are given by the developers with it, so we have to configure these things manually.I come across a lots of videos on youtube to configure graphics in codeblocks and i found all the videos are just waste of time except one video and i learnt  from that video .It was a bit difficult for me to configure graphics in codeblocks.
This is why because i was getting the libraries and header file with bug.
So i thought to create a video on this topic on my own  :How to use graphics in codeblocks video






  If you did these two things then you can use this program or concept to insert images in C++ language using graphics in Codeblocks.
Here we go:
 #include<iostream>  
 #include<graphics.h>  
 int main()  
 {  
   initwindow(600,400,"Images");  
   readimagefile("image_name.jpg",0,0,600,400);  
   getch();  
   readimagefile("image_name.jpg",0,0,600,400);  
   getch();  
   return 0;  
 }  



Description of the program:


If you are using code blocks to make programs in graphics mode then we can make the programs in only C++ because in the graphics.h header file there is reference to iostream and if we work in C language then it will not link and then we get error in header file graphics.h. Download File



here we have used the two important predefinded functions of graphics they are....

  • initwindow():this function is used to initialise a new window or you can say a  new window
  • readimagefile():this is the function that is used to set images in our program.
readimagefile() takes five parameters the first parameter is the name of the image with extension of the image and the rest are the co-ordinates of the screen where to set.


Thanks for visiting ...we will come with new typical programs so stay connected.







How to insert image in c language in turboc IDE

Its been very interesting as well as difficult to work with graphics in c or c++ languages.
But it will be more interesting to work with image insertion in C or C++ language.

I have already created the post to insert image in c/c++ in codeblocks IDE but now its time to achieve this using Turbo C++ IDE.

 Befor writing code we have to take care of  these points.
  • Create a  bmp(16 color Bitmap) image file using paint or any other image editor. 
  • paste that file into bin folder of turbo c where this program will be saved.
  • After pasting we will continue to write the below code.




 
 #include <alloc.h>  
   #include <conio.h>  
   #include <graphics.h>  
   #include <stdio.h>  
   #include <stdlib.h>  
   struct BMP  
   {  
    char Type[2];      //File type. Set to "BM".  
    unsigned long Size;   //Size in BYTES of the file.  
    unsigned long Reserved;   //Reserved. Set to zero.  
    unsigned long OffSet;  //Offset to the data.  
    unsigned long headsize; //Size of rest of header. Set to 40.  
    unsigned long Width;   //Width of bitmap in pixels.  
    unsigned long Height;   // Height of bitmap in pixels.  
    unsigned int Planes;  //Number of Planes. Set to 1.  
    unsigned int BitsPerPixel;    //Number of Bits per pixels.  
    unsigned long Compression;  //Compression. Usually set to 0.  
    unsigned long SizeImage; //Size in bytes of the bitmap.  
    unsigned long XPixelsPreMeter;   //Horizontal pixels per meter.  
    unsigned long YPixelsPreMeter;   //Vertical pixels per meter.  
    unsigned long ColorsUsed;  //Number of colors used.  
    unsigned long ColorsImportant; //Number of "important" colors.  
   };  
   int ShowBMP(int x, int y, char* FileName)  
   {  
     int b,a;  
     struct BMP Obj;  
     unsigned char* Datas;  
     int in=0;  
     unsigned char c=0;  
     FILE * fp;  
     fp = fopen(image.bmp,"rb"); //give filename of image with extension.  
     if(!fp){  
     printf("Error : Unable to open file ..");  
     exit(0);  
     }  
     fread(&Obj, sizeof(Obj), 1, fp);  
     if(Obj.BitsPerPixel!=4) // This isn't a 16 color bmp we can read;  
     {  
      fclose(fp);  
      printf("Error : File format not supported ..");  
      exit(0);  
     };  
     fseek(fp,Obj.OffSet,SEEK_SET);  
     Datas=(unsigned char*) calloc(Obj.Width/2+1, sizeof(unsigned char));  
     for(b=Obj.Height;b>=0;b--)  
     {  
      fread(Datas, sizeof(unsigned char), Obj.Width/2, fp);  
      c=0;  
      in=0;  
      for(a=0;a<=Obj.Width;a+=2)  
      {  
        c = (Datas[in] | 0x00) >>4;  
        putpixel(a+x,b+y,c);  
        c = (Datas[in] | 0xF0) & 0x0F;  
         putpixel(a+1+x,b+y,c);  
        in++;  
      }  
     }  
     free (Datas);  
     fclose(fp);  
     return 1;  
   }  
   void main()  
   {  
   int color;  
   int gd , gm ;  
   gd = VGA ; gm = VGAHI;  
   initgraph(&gd,&gm,"");  
   ShowBMP(0,0,"j.bmp"); /* Enter File Name Here */  
   getch();  
   closegraph();  
   }  

Now Run the code and you will get your image as output.
 
 

How to implement Facebook audience network banner ad in android app using Android Studio

Its very simple to implement Facebook audience network banner ad in android app using Android Studio. We will complete it in 4 Steps. 1. ...