Skip to main content

Posts

Bring Android application to forground

Intent launchApp = new Intent(context, Applications_MainActivity.class);                             launchApp.setAction(Intent.ACTION_MAIN);                             launchApp.addCategory(Intent.CATEGORY_LAUNCHER);                             launchApp.setFlags(IConstants.NOTIFICATION_FLAG);//Use this Special Flag                             context.getApplicationContext().startActivity(launchApp); Update below value in your Constants File,   public static final int NOTIFICATION_FLAG = 0x10200000;

IS MY SERVICE RUNNING? - DISPLAY ALL RUNNING SERVICES IN ANDROID

Compare your service name with class name of running services to find out your service is running or not. ActivityManager activityManager= (ActivityManager)getSystemService(ACTIVITY_SERVICE);         for (RunningServiceInfo service : activityManager.getRunningServices(Integer.MAX_VALUE)) {             Log.i("Service", "Process " + service.process + " with component " + service.service.getClassName());         }             

Code : Reading files from Assets folder

Reading File from Assets Folder AssetManager assetManager = getApplicationContext().getAssets();         InputStream is = assetManager .open("filename.txt");         BufferedReader reader = new BufferedReader(new InputStreamReader(is));         StringBuilder sb = new StringBuilder();         String line = null;         while ((line = reader.readLine()) != null) {           sb.append(line + "\n");         }         is.close();       String dataString = sb.toString();

Linear Layout with border

Save this xml with name border.xml and add as a background for the linear layout....  <shape xmlns:android=" http://schemas.android.com/apk/res/android ">     <stroke android:width="4dp" android:color="#FF00FF00" />     <solid android:color="#ffffff" />     <padding android:left="7dp" android:top="7dp"             android:right="7dp" android:bottom="7dp" />     <corners android:radius="4dp" /> </shape>

Playing wav File in android using Audio Track

To play a wav file read the wav file and pass the bytes to audio track chunck by chunk. private void playWaveFile(){                 // define the buffer size for audio track         int minBufferSize = AudioTrack.getMinBufferSize(8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);         int bufferSize = 512;         AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_VOICE_CALL, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, minBufferSize, AudioTrack.MODE_STREAM);         String filepath = "File Path";         int count = 0;         byte[] data = new byte[bufferSize];         try {             FileInputStream fileInp...