Posts

Convert Bitmap image into PDF using Glide and share PDF using intent android.

public class GlideUtils {     private ProgressDialog progressDialog;     public void downloadImageUsingGlide(String imageUrl, Context mContext, String imgName) {         String imgUrl = imageUrl;         int index = imgUrl.lastIndexOf('/') + 1; //        final String imgName = imgUrl.substring(index);         final String imageFormat = getImageType(imgUrl);         Glide.with(mContext)                 .asBitmap()                 .load(imgUrl)                 .into(new CustomTarget<Bitmap>() {                     @Override                     public void onResourceReady(@NonNull Bitmap bitmap, @Nullable Transition<? super Bitmap...

QR code scanner using Zxing library. Scanner for android

//Scanner activity to scan data and get result. This can be called from other activity and get a result as required. //You can call scan Activity from any where and get value as reuired and can get type of qr code for example(URI,Text) public class ScanActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler { private static final int REQUEST_CAMERA = 1; private static int camId = Camera.CameraInfo. CAMERA_FACING_BACK ; private ZXingScannerView mScannerView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mScannerView = new ZXingScannerView(this); setContentView(mScannerView); int currentApiVersion = Build.VERSION. SDK_INT ; if (currentApiVersion >= Build.VERSION_CODES. M ) { if (checkPermission()) { Toast.makeText(getApplicationContext(), "Permission already granted!", Toast.LENGT...

Restrict application to be open in rooted phone android.

public Boolean isDeviceRooted(Context context){ boolean isRooted = isrooted1() || isrooted2(); return isRooted; } private boolean isrooted1() { File file = new File( "/system/app/Superuser.apk" ); if (file.exists()) { return true ; } return false ; } // try executing commands private boolean isrooted2() { return canExecuteCommand ( "/system/xbin/which su" ) || canExecuteCommand ( "/system/bin/which su" ) || canExecuteCommand ( "which su" ); } private static boolean canExecuteCommand(String command) { boolean executedSuccesfully; try { Runtime. getRuntime ().exec(command); executedSuccesfully = true ; } catch (Exception e) { executedSuccesfully = false ; } return executedSuccesfully; }

Send data to particular whatsapp number android. Sharing data using whatsapp.

String[] phonecontain = request.split("phone="); Intent sendIntent = new Intent("android.intent.action.MAIN"); PackageInfo info = pm.getPackageInfo("com.whatsapp",  PackageManager.GET_META_DATA);                //Check if package exists or not. If not then code  //in catch block will be called  sendIntent.setPackage("com.whatsapp");   //sendIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));                 sendIntent.setAction(Intent.ACTION_SEND); sendIntent.setType("text/plain"); // sendIntent.putExtra(Intent.EXTRA_TEXT, ""); // sendIntent.putExtra("jid", "9764544315" + "@s.whatsapp.net"); //phone number without "+" prefix sendIntent.setComponent(new ComponentName("com.whatsapp","com.whatsapp.Conversation")); sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators(phonecontain[1])+...

start Implicit intent and allow them to download if that external activity is not available.

  Intent intent =new Intent(Intent.ACTION_DIAL, Uri.parse(“tel:555-2368”));   // Check if an Activity exists to perform this action.   PackageManager pm = getPackageManager();   ComponentName cn = intent.resolveActivity(pm);   if (cn == null)   {          // If there is no Activity available to perform the action         // Check to see if the Google Play Store is available.         Uri marketUri =      Uri.parse(“market://search?q=pname:com.myapp.packagename”);         Intent marketIntent = new       Intent(Intent.ACTION_VIEW).setData(marketUri);           // If the Google Play Store is available, use it to download an application  // capable of performing the required action. Otherwise, log an  // error.          if (marketIntent.resolveActivity...

Storing captured image or an image picked from a gallery in internal storage using file provider android.

Android Camera intent not working in android nougat and above. File provider used to capture an image and pick an image from the gallery.  Capture image from the camera and stored in the internal storage in android nougat and above. It will show you how to use  File Provider  when you set your target SDK as 24 and change following. 1) Create file_path.xml <? xml version= "1.0" encoding= "utf-8" ?> < paths xmlns: android = "http://schemas.android.com/apk/res/android" > < external-path name= "external_files" path= "." /> </ paths > 2) In AndroidMainfest inside application tag //Here authoitties is unique identification of the fileprovider < provider android :name= "android.support.v4.content.FileProvider" android :authorities= "${applicationId}.fileProvider" android :exported= "false" android :grantUriPermissions= "true" > ...

Store GPS Location in image background android.

Store GPS Location in image background android, store latitude and longitude value in the image. Solution: ExifInterface exif; //get the value from google or network operator. double latitude = getLatitude(); double longitude = getLongitude(); try { //pass image file name after capturing an image or an image picked from the gallery.     exif = new ExifInterface("/sdcard/DCIM/"+filename+".jpeg");     int num1Lat = (int)Math.floor(latitude);     int num2Lat = (int)Math.floor((latitude - num1Lat) * 60);     double num3Lat = (latitude - ((double)num1Lat+((double)num2Lat/60))) * 3600000;     int num1Lon = (int)Math.floor(longitude);     int num2Lon = (int)Math.floor((longitude - num1Lon) * 60);     double num3Lon = (longitude - ((double)num1Lon+((double)num2Lon/60))) * 3600000; //saveAttributes to exif     exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, num1Lat+"/1,"+num2Lat+"/...