Posts

Showing posts from January, 2021

Code for Battery Percentage

 Set these codes in the first "add source directly": BatteryManager bm=(BatteryManager)getSystemService(BATTERY_SERVICE); int battery_percent = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY); textview1.setText(battery_percent + "%"); Set these codes on the 2nd "add source directly": IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent batteryStatus = registerReceiver(null, ifilter); int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1); if(status == BatteryManager.BATTERY_STATUS_FULL) { Toast.makeText(getApplicationContext(),"Device is fully charged",Toast.LENGTH_LONG).show(); } else { Toast.makeText(getApplicationContext(),"Device is not fully charged",Toast.LENGTH_LONG).show(); }

Code for common share button

 Here are the codes: Intent i = new Intent(android.content.Intent.ACTION_SEND); i.setType("text/plain"); i.putExtra(android.content.Intent.EXTRA_SUBJECT, a); i.putExtra(android.content.Intent.EXTRA_TEXT, b); startActivity(Intent.createChooser(i,"Share using")); Thanks.......

Code for "Image share from app"

 Copy these codes: Bitmap bm = ((android.graphics.drawable.BitmapDrawable) imageview1.getDrawable()).getBitmap(); try { java.io.File file = new java.io.File(getExternalCacheDir() + "/image.jpg"); java.io.OutputStream out = new java.io.FileOutputStream(file); bm.compress(Bitmap.CompressFormat.JPEG, 100, out); out.flush(); out.close(); } catch (Exception e) { showMessage(e.toString()); } Intent iten = new Intent(android.content.Intent.ACTION_SEND); iten.setType("*/*"); iten.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new java.io.File(getExternalCacheDir() + "/image.jpg"))); startActivity(Intent.createChooser(iten, "Send image")); Thanks........

Code for Seek bar Sound up-down

 Set these codes in the "On Activity Create": audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); seekbar1.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC));} AudioManager audioManager; private void nothing() { Set these codes on the Seek Bar On Progress Changed: textview1.setText("Music Volume : " + _progressValue); audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, _progressValue, 0); Thank you.....

Code for "Loading Dialog Box"

Here are the codes: final ProgressDialog prog = new ProgressDialog(MainActivity.this); prog.setMax(100);prog.setTitle("Enter_Title_Here"); prog.setMessage("Please wait..."); prog.setIndeterminate(true); prog.setCancelable(true);prog.show();   Thank You......

Code for Text_Share

 Copy these and paste in "add source directly"... Intent i = new Intent(android.content.Intent.ACTION_SEND); i.setType("text/plain"); i.putExtra(android.content.Intent.EXTRA_SUBJECT, a); i.putExtra(android.content.Intent.EXTRA_TEXT, b); startActivity(Intent.createChooser(i,"Share using")); Thank you..... Get the video here: https://youtu.be/-dV_N1vg6pY Get all sketchware tutorials here: https://youtube.com/playlist?list=PLBJuGex9TxtGLZllla7bwqhPl53Tldd8o Please subscribe my channel: https://youtu.be/1u1-msbf9P0

Code for Bluetooth

 Copy these: android.bluetooth.BluetoothAdapter bluetoothAdapter = android.bluetooth.BluetoothAdapter.getDefaultAdapter(); boolean isEnabled = bluetoothAdapter.isEnabled(); if (_enable && !isEnabled) { bluetoothAdapter.enable(); } else if(!_enable && isEnabled) { bluetoothAdapter.disable(); } Thanks...

Code for Notification

Please copy these Notification.Builder mBuilder = new Notification.Builder(MainActivity.this); mBuilder.setSmallIcon(R.drawable.app_icon); mBuilder.setContentTitle("Sketchware"); mBuilder.setContentText("Hello how are you?"); mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify((int)num, mBuilder.build()); Thank you....