Wednesday, 5 October 2016

Repeatedly Running Tast (TimerTask)

TimerTask task;

Timer timer;

        if (timer != null) {
            timer.cancel();
        }

        timer = new Timer();

        final Handler handler = new Handler();

        task = new TimerTask() {
            @Override
            public void run() {

                handler.post(new Runnable() {
                    @Override
                    public void run() {

                    // Do Thing you want to excute
                    }
                });
            }
        };

        timer.schedule( task, 0, 15000);



// Stop the Task

timer.cancel();

Make Call Directly

<Java Code>
Intent shortcutIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + Uri.encode(code)));                        startActivity(shortcutIntent);

<App Permission>

<uses-permission android:name="android.permission.CALL_PHONE" />

Check Internet Connectivity

<Java Method>

public static boolean isNetworkAvailable(Context context)
    {

        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        return activeNetworkInfo != null && activeNetworkInfo.isConnected();

    }


<App Permission>
<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Run Task when app start

SharedPreferences preferences;
boolean isFirstRun;


// In Onstart Method

preferences = PreferenceManager.getDefaultSharedPreferences(this);

            isFirstRun = preferences.getBoolean("FIRSTRUN", true);


            if (isFirstRun) {

                SharedPreferences.Editor editor = preferences.edit();
                editor.putBoolean("FIRSTRUN", false);
                editor.commit();
            } else {

           
            }

Android Notification

Intent intenT = new Intent(this, Target.class);

PendingIntent pi = PendingIntent.getActivity(NotifyService.this, 0, intenT, PendingIntent.FLAG_UPDATE_CURRENT);
                Resources r = getResources();

                Notification notification = new NotificationCompat.Builder(NotifyService.this)
                        .setTicker("Jobs Updates Founds")
                        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setContentTitle(arrayList_Title.get(0))
                        .setPriority(Notification.PRIORITY_MAX)
                        .setVibrate(new long[]{100, 100})
                        .setStyle(new NotificationCompat.BigTextStyle())
                        .setContentIntent(pi)
                        .setAutoCancel(true)
                        .build();
                NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                notificationManager.notify(0, notification);

Array list to String



String a=Arrays.toString(Test_Array.toArray()).replaceAll("\\[|\\]", "").replaceAll(" ","\t");

Or

                      String str = Id_Array.toString();
                       System.out.println("Step-1 : " + str);

                       str = str.replaceAll("[\\[\\]]", "").replaceAll(" ", "");

                       System.out.println("Step-2 : " + str);

Publish by KASHIF AHMED