This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void saveFile(Bitmap bitmap) { | |
| FileOutputStream out = null; | |
| String path = Environment.getExternalStorageDirectory().toString(); | |
| try { | |
| out = new FileOutputStream(path + "/don.jpg"); | |
| bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } finally { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class DownloadFileFromURL extends AsyncTask<String, String, String> { | |
| @Override | |
| protected void onPreExecute() { | |
| super.onPreExecute(); | |
| pDialog = new ProgressDialog(MainActivity.this); | |
| pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); | |
| pDialog.setMessage("downloading...."); | |
| pDialog.setCancelable(false); | |
| pDialog.show(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private boolean isNetworkConnected() { | |
| ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); | |
| return cm.getActiveNetworkInfo() != null; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void alertDialogue(){ | |
| AlertDialog.Builder builder; | |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
| builder = new AlertDialog.Builder(MainActivity.this, android.R.style.Theme_Material_Dialog_Alert); | |
| } else { | |
| builder = new AlertDialog.Builder(MainActivity.this); | |
| } | |
| builder.setTitle("Delete entry") | |
| .setMessage("Are you sure you want to delete this entry?") | |
| .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <receiver android:name=".AlarmReceiver"></receiver> | |
| private AlarmManager alarmMgr; | |
| private PendingIntent alarmIntent; | |
| alarmMgr = (AlarmManager)this.getSystemService(Context.ALARM_SERVICE); | |
| Intent intent = new Intent(this, AlarmReceiver.class); | |
| alarmIntent = PendingIntent.getBroadcast(this, 0, intent, 0); | |
| alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Timer t = new Timer(); | |
| t.schedule(new TimerTask() { | |
| @Override | |
| public void run() { | |
| System.out.println("Hello World"); | |
| } | |
| }, 0, 5000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private boolean isMyServiceRunning(Class<?> serviceClass) { | |
| ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); | |
| for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { | |
| if (serviceClass.getName().equals(service.service.getClassName())) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void hideIcon() { | |
| PackageManager p = getPackageManager(); | |
| ComponentName componentName = new ComponentName(this, com.test.elementz.simpleservice.MainActivity.class); // activity which is first time open in manifiest file which is declare as <category android:name="android.intent.category.LAUNCHER" /> | |
| p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| IntentFilter filter2 = new IntentFilter(); | |
| filter2.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED); | |
| filter2.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); | |
| myReceiver=new MyReceiver(); | |
| registerReceiver(myReceiver, filter2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // compile 'dev.dworks.libs:volleyplus:+' | |
| SimpleMultiPartRequest smr = new SimpleMultiPartRequest(Request.Method.POST, UPLOAD_URL, | |
| new Response.Listener<String>() { | |
| @Override | |
| public void onResponse(String response) { | |
| Log.d("Response", response); | |
| try { | |
| JSONObject jObj = new JSONObject(response); |