· 8 years ago · May 05, 2018, 12:08 PM
1NotifFrag.java--------------
2
3public class NotificationFrag extends Fragment {
4
5 DatabaseHelper dbhelper;
6 CustomAdapter customAdapter;
7 List<App> list = new ArrayList<>();
8 BroadcastReceiver myReciever;
9 public static NotificationFrag newInstance() {
10 NotificationFrag fragment = new NotificationFrag();
11 return fragment;
12 }
13
14
15 @Override
16 public View onCreateView(LayoutInflater inflater, ViewGroup container,
17 Bundle savedInstanceState) {
18 View view = inflater.inflate(R.layout.notification_frag, container, false);
19 ListView lvApps = view.findViewById(R.id.lv_notif);
20
21
22 lvApps.setOnItemClickListener(new AdapterView.OnItemClickListener() {
23 @Override
24 public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
25 AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
26 View viewDialogue = getActivity().getLayoutInflater().inflate(R.layout.view_dialog_layout,null);
27 TextView tvName = viewDialogue.findViewById(R.id.tv_app_name);
28 TextView tvMsg = viewDialogue.findViewById(R.id.tv_msg_body);
29 TextView tvTime = viewDialogue.findViewById(R.id.tv_time);
30 ImageView ivIcon = viewDialogue.findViewById(R.id.iv_icon);
31 tvMsg.setText(list.get(position).getData());
32 tvTime.setText(list.get(position).getLastTime());
33 ImageButton ibInfo = viewDialogue.findViewById(R.id.bt_info);
34 ImageButton ibLaunch = viewDialogue.findViewById(R.id.bt_launch);
35 ImageButton ibDel = viewDialogue.findViewById(R.id.bt_delete);
36 Drawable icon;
37 final PackageManager pm = getActivity().getPackageManager();
38 ApplicationInfo ai;
39 try {
40 icon = pm.getApplicationIcon(list.get(position).getAppName());
41 ai = pm.getApplicationInfo( list.get(position).getAppName(), 0);
42 final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : list.get(position).getAppName());
43
44 ivIcon.setImageDrawable(icon);
45 tvName.setText(applicationName);
46 } catch (PackageManager.NameNotFoundException e) {
47 e.printStackTrace();
48 }
49 alertDialogBuilder.setView(viewDialogue);
50 final AlertDialog alertDialog = alertDialogBuilder.create();
51 ibInfo.setOnClickListener(new View.OnClickListener() {
52 @Override
53 public void onClick(View v) {
54 alertDialog.dismiss();
55 Intent intent = new Intent();
56 intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
57 Uri uri = Uri.fromParts("package",list.get(position).getAppName(), null);
58 intent.setData(uri);
59 startActivity(intent);
60 }
61 });
62 ibLaunch.setOnClickListener(new View.OnClickListener() {
63 @Override
64 public void onClick(View v) {
65 alertDialog.dismiss();
66 Intent i = getActivity().getPackageManager().getLaunchIntentForPackage(list.get(position).getAppName());
67 startActivity(i);
68 }
69 });
70 ibDel.setOnClickListener(new View.OnClickListener() {
71 @Override
72 public void onClick(View v) {
73 alertDialog.dismiss();
74 AlertDialog.Builder alertDialogBuilder2 = new AlertDialog.Builder(getActivity());
75 alertDialogBuilder2.setMessage("Do you really wnt to delete this record?");
76
77 alertDialogBuilder2.setPositiveButton("Yes",
78 new DialogInterface.OnClickListener() {
79 @Override
80 public void onClick(DialogInterface arg0, int arg1) {
81 dbhelper.deleteSingleItem(list.get(position));
82 list.remove(position);
83 customAdapter.notifyDataSetChanged();
84 }
85 });
86 alertDialogBuilder2.setNegativeButton("No",
87 new DialogInterface.OnClickListener() {
88 @Override
89 public void onClick(DialogInterface arg0, int arg1) {
90 }
91 });
92 final AlertDialog alertDialog2 = alertDialogBuilder2.create();
93 alertDialog2.show();
94 }
95 });
96 alertDialog.show();
97 }
98 });
99
100 lvApps.setEmptyView(view.findViewById(R.id.ll_no_item));
101 dbhelper = new DatabaseHelper(getActivity());
102 list = dbhelper.getAllApps("Notif");
103 customAdapter = new CustomAdapter(list,getActivity());
104 lvApps.setAdapter(customAdapter);
105
106 myReciever = new BroadcastReceiver() {
107 @Override
108 public void onReceive(Context context, Intent intent) {
109 if(customAdapter!=null){
110 list.clear();
111 list.addAll(dbhelper.getAllApps("Notif"));
112 customAdapter.notifyDataSetChanged();
113 }
114 }
115 };
116
117 return view ;
118 }
119 @Override
120 public void onResume() {
121 super.onResume();
122 getActivity().registerReceiver(myReciever,new IntentFilter("android.intent.action.MAIN"));
123 }
124
125 @Override
126 public void onPause() {
127 super.onPause();
128 getActivity().unregisterReceiver(myReciever);
129 }
130}
131
132
133ToastFrag----------------------------------------
134public class ToastFrag extends Fragment {
135
136 DatabaseHelper dbhelper;
137 CustomAdapter customAdapter;
138 List<App> list = new ArrayList<>();
139 BroadcastReceiver myReciever;
140
141 public static ToastFrag newInstance() {
142 ToastFrag fragment = new ToastFrag();
143 return fragment;
144 }
145 @Override
146 public View onCreateView(LayoutInflater inflater, ViewGroup container,
147 Bundle savedInstanceState) {
148 View view = inflater.inflate(R.layout.toast_frag, container, false);
149 ListView lvApps = view.findViewById(R.id.lv_toast);
150
151 lvApps.setOnItemClickListener(new AdapterView.OnItemClickListener() {
152 @Override
153 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
154
155 }
156 });
157
158 dbhelper = new DatabaseHelper(getActivity());
159 list = dbhelper.getAllApps("Toast");
160 customAdapter = new CustomAdapter(list,getActivity());
161 lvApps.setAdapter(customAdapter);
162 myReciever = new BroadcastReceiver() {
163 @Override
164 public void onReceive(Context context, Intent intent) {
165 if(customAdapter!=null){
166 list.clear();
167 list.addAll(dbhelper.getAllApps("Toast"));
168 customAdapter.notifyDataSetChanged();
169 }
170 }
171 };
172
173
174 return view ;
175 }
176 @Override
177 public void onResume() {
178 super.onResume();
179 getActivity().registerReceiver(myReciever,new IntentFilter("android.intent.action.MAIN"));
180 }
181
182 @Override
183 public void onPause() {
184 super.onPause();
185 getActivity().unregisterReceiver(myReciever);
186 }
187}
188
189Access----------------------------------------------
190public class Access extends AccessibilityService {
191
192 DatabaseHelper dbhelper;
193
194 @Override
195 public void onAccessibilityEvent(AccessibilityEvent event) {
196 dbhelper = new DatabaseHelper(getBaseContext());
197 if (event.getEventType() != AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED)
198 return; // event is not a notification
199
200 String sourcePackageName = (String) event.getPackageName();
201
202 Parcelable parcelable = event.getParcelableData();
203 if (parcelable instanceof Notification) {
204 // Statusbar Notification
205 String log = "Message: " + event.getText().get(0)
206 + " [Source: " + sourcePackageName + "]";
207 // write `log` to file...
208 Log.i("MSG",log);
209 dbhelper.insertData(sourcePackageName,"Notif",event.getText().get(0).toString());
210 Intent i = new Intent("android.intent.action.MAIN");
211 this.sendBroadcast(i);
212 }
213 else {
214 // something else, e.g. a Toast message
215 String log = "Message: " + event.getText().get(0)
216 + " [Source: " + sourcePackageName + "]";
217 // write `log` to file...
218 Log.i("MSG",log);
219 dbhelper.insertData(sourcePackageName,"Toast",event.getText().get(0).toString());
220 Intent i = new Intent("android.intent.action.MAIN");
221 this.sendBroadcast(i);
222 }
223 }
224
225 @Override
226 public void onInterrupt() {
227
228 }
229 @Override
230 protected void onServiceConnected() {
231 AccessibilityServiceInfo info = new AccessibilityServiceInfo();
232 info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
233 info.feedbackType = AccessibilityServiceInfo.FEEDBACK_ALL_MASK;
234 info.notificationTimeout = 100;
235 setServiceInfo(info);
236 }
237}
238App------------------------------------
239
240public class App {
241 private String appName;
242 private String lastTime;
243 private String typeOfInstance;
244 private int id;
245 private String data;
246 public static final String TABLE_NAME = "notifandtoastsdata";
247 public static final String COLUMN_ID = "id";
248 public static final String APP_NAME = "name";
249 public static final String INSTANCE_TYPE = "typeofd";
250 public static final String COLUMN_TIMESTAMP = "timestamp";
251 public static final String DATA = "data";
252
253 public static final String CREATE_TABLE =
254 "CREATE TABLE " + TABLE_NAME + "("
255 + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
256 + APP_NAME + " TEXT,"
257 + DATA + " TEXT,"
258 + INSTANCE_TYPE + " TEXT,"
259 + COLUMN_TIMESTAMP + " DATETIME DEFAULT CURRENT_TIMESTAMP"
260 + ")";
261 public String getData() {
262 return data;
263 }
264
265 public void setData(String data) {
266 this.data = data;
267 }
268 public int getId() {
269 return id;
270 }
271
272 public void setId(int id) {
273 this.id = id;
274 }
275
276 public String getTypeOfInstance() {
277 return typeOfInstance;
278 }
279
280 public void setTypeOfInstance(String typeOfInstance) {
281 this.typeOfInstance = typeOfInstance;
282 }
283
284 public String getAppName() {
285 return appName;
286 }
287
288 public void setAppName(String appName) {
289 this.appName = appName;
290 }
291
292 public String getLastTime() {
293 return lastTime;
294 }
295
296 public void setLastTime(String lastTime) {
297 this.lastTime = lastTime;
298 }
299
300
301}
302CustomAdapter-----------------------------------------------
303public class CustomAdapter extends BaseAdapter {
304 List<App> list ;
305 Activity activity;
306 public CustomAdapter(List<App> list, Activity activity) {
307 this.list = list;
308 this.activity = activity;
309 }
310
311 @Override
312 public int getCount() {
313 return list.size();
314 }
315
316 @Override
317 public Object getItem(int position) {
318 return list.get(position);
319 }
320
321 @Override
322 public long getItemId(int position) {
323 return position;
324 }
325
326 @Override
327 public View getView(int position, View convertView, ViewGroup parent) {
328 LayoutInflater anInflater = activity.getLayoutInflater();
329 View view= anInflater.inflate(R.layout.item_layout, null);
330 TextView tvAppName = view.findViewById(R.id.tv_app_name);
331 TextView tvLastTime = view.findViewById(R.id.tv_last_time);
332 TextView tvdata = view.findViewById(R.id.tv_app_data);
333 ImageView imageView = view.findViewById(R.id.iv_icon);
334
335
336 final PackageManager pm = activity.getPackageManager();
337 ApplicationInfo ai;
338 SimpleDateFormat formatter1= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
339 SimpleDateFormat formatter2= new SimpleDateFormat("dd/MM/yy HH:mm");
340 Date date1;
341 try {
342 date1 = formatter1.parse(list.get(position).getLastTime());
343 tvLastTime.setText(formatter2.format(date1));
344 } catch (ParseException e) {
345 e.printStackTrace();
346 }
347
348 tvdata.setText(list.get(position).getData());
349 try {
350 Drawable icon = pm.getApplicationIcon(list.get(position).getAppName());
351 ai = pm.getApplicationInfo( list.get(position).getAppName(), 0);
352 final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : list.get(position).getAppName());
353
354 imageView.setImageDrawable(icon);
355 tvAppName.setText(applicationName);
356 }
357 catch (PackageManager.NameNotFoundException e) {
358 e.printStackTrace();
359 }
360 return view;
361 }
362}
363DatabaseHelper------------------------------------
364public class DatabaseHelper extends SQLiteOpenHelper {
365
366 // Database Version
367 private static final int DATABASE_VERSION = 2;
368
369 // Database Name
370 private static final String DATABASE_NAME = "notif_toast_db";
371
372
373 public DatabaseHelper(Context context) {
374 super(context, DATABASE_NAME, null, DATABASE_VERSION);
375 }
376
377 // Creating Tables
378 @Override
379 public void onCreate(SQLiteDatabase db) {
380
381 // create notes table
382 db.execSQL(App.CREATE_TABLE);
383 }
384
385 // Upgrading database
386 @Override
387 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
388 // Drop older table if existed
389 db.execSQL("DROP TABLE IF EXISTS " + App.TABLE_NAME);
390
391 // Create tables again
392 onCreate(db);
393 }
394
395 public long insertData(String appName,String type,String data) {
396 // get writable database as we want to write data
397 SQLiteDatabase db = this.getWritableDatabase();
398
399 ContentValues values = new ContentValues();
400 // `id` and `timestamp` will be inserted automatically.
401 // no need to add them
402 values.put(App.APP_NAME, appName);
403 values.put(App.INSTANCE_TYPE, type);
404 values.put(App.DATA, data);
405
406 // insert row
407 long id = db.insert(App.TABLE_NAME, null, values);
408
409 // close db connection
410 db.close();
411
412 // return newly inserted row id
413 return id;
414 }
415
416 public List<App> getAllApps(String type) {
417 List<App> apps = new ArrayList<>();
418 // Select All Query
419 String selectQuery = "SELECT * FROM " + App.TABLE_NAME +" WHERE "+App.INSTANCE_TYPE + " = '"+ type + "' ORDER BY " + App.COLUMN_TIMESTAMP + " DESC";
420
421 SQLiteDatabase db = this.getWritableDatabase();
422 Cursor cursor = db.rawQuery(selectQuery, null);
423
424 // looping through all rows and adding to list
425 if (cursor.moveToFirst()) {
426 do {
427 App app = new App();
428 app.setId(cursor.getInt(cursor.getColumnIndex(App.COLUMN_ID)));
429 app.setAppName(cursor.getString(cursor.getColumnIndex(App.APP_NAME)));
430 app.setLastTime(cursor.getString(cursor.getColumnIndex(App.COLUMN_TIMESTAMP)));
431 app.setTypeOfInstance(cursor.getString(cursor.getColumnIndex(App.INSTANCE_TYPE)));
432 app.setData(cursor.getString(cursor.getColumnIndex(App.DATA)));
433
434 apps.add(app);
435 } while (cursor.moveToNext());
436 }
437
438 // close db connection
439 db.close();
440
441 // return notes list
442 return apps;
443 }
444 public void deleteSingleItem(App app){
445 SQLiteDatabase db = this.getWritableDatabase();
446 db.delete(App.TABLE_NAME, App.COLUMN_ID + " = ?",
447 new String[]{String.valueOf(app.getId())});
448 db.close();
449 }
450 public void deleteList(String type){
451 SQLiteDatabase db = this.getWritableDatabase();
452 db.delete(App.TABLE_NAME, App.INSTANCE_TYPE + " = ?",
453 new String[]{type});
454 db.close();
455 }
456}
457MainActivity------------------------------------------------------
458public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
459 Fragment selectedFragment = null;
460 DatabaseHelper dbHelper;
461 DrawerLayout drawer;
462 SharedPreferences sharedPreferences;
463 Switch swService;
464 Spinner sp;
465 String[] listDelete = { "Disable", "12 Hours", "24 Hours", "48 Hours", "1 Week" };
466 AlertDialog.Builder builder;
467 @Override
468 protected void onCreate(Bundle savedInstanceState) {
469 super.onCreate(savedInstanceState);
470 setContentView(R.layout.layout_with_drawer);
471 Toolbar toolbar = findViewById(R.id.toolbar);
472 setSupportActionBar(toolbar);
473
474
475 sharedPreferences = getSharedPreferences("FIRST_RUN", 0);
476 final SharedPreferences.Editor editor = sharedPreferences.edit();
477
478
479 drawer = findViewById(R.id.drawer_layout);
480 ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
481 this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
482 drawer.addDrawerListener(toggle);
483 toggle.syncState();
484
485 NavigationView navigationView = findViewById(R.id.nav_view);
486 navigationView.setNavigationItemSelectedListener(this);
487
488
489
490 swService = (Switch) navigationView.getMenu().findItem(R.id.nav_service).getActionView();
491 swService.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
492 @Override
493 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
494 Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
495 startActivityForResult(intent, 0);
496 }
497 });
498
499
500 final ArrayAdapter<String> adp = new ArrayAdapter<String>(MainActivity.this,
501 android.R.layout.simple_spinner_item, listDelete);
502
503 //textView = findViewById(R.id.txt1);
504 adp.setDropDownViewResource(android.R.layout.select_dialog_singlechoice);
505
506 sp = new Spinner(MainActivity.this);
507 sp.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
508 sp.setAdapter(adp);
509
510 if(sharedPreferences.getString("spData","").equals("")){
511 sp.setSelection(0);
512 }else{
513 sp.setSelection(Arrays.asList(listDelete).indexOf(sharedPreferences.getString("spData","")));
514 }
515 builder = new AlertDialog.Builder(MainActivity.this);
516 builder.setView(sp);
517 builder.setNegativeButton("Cancel",
518 new DialogInterface.OnClickListener() {
519 @Override
520 public void onClick(DialogInterface arg0, int arg1) {
521 // sp.setSelection(sharedPreferences.getString("spData",listDelete[0]));
522 if(sharedPreferences.getString("spData","").equals("")){
523 sp.setSelection(0);
524 }else{
525 sp.setSelection(Arrays.asList(listDelete).indexOf(sharedPreferences.getString("spData","")));
526 }
527 }
528 });
529 builder.setPositiveButton("Ok",
530 new DialogInterface.OnClickListener() {
531 @Override
532 public void onClick(DialogInterface arg0, int arg1) {
533
534 editor.putString("spData", sp.getSelectedItem().toString());
535
536 }
537 });
538
539 dbHelper = new DatabaseHelper(MainActivity.this);
540 FloatingActionButton fabDeleteAll = findViewById(R.id.fab_delete_all);
541 fabDeleteAll.setOnClickListener(new View.OnClickListener() {
542 @Override
543 public void onClick(View v) {
544
545 AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
546 alertDialogBuilder.setMessage("Are you sure you want to delete All records?");
547 alertDialogBuilder.setPositiveButton("Yes",
548 new DialogInterface.OnClickListener() {
549 @Override
550 public void onClick(DialogInterface arg0, int arg1) {
551 if(selectedFragment instanceof NotificationFrag){
552 dbHelper.deleteList("Notif");
553 Intent i = new Intent("android.intent.action.MAIN");
554 sendBroadcast(i);
555 }else if(selectedFragment instanceof ToastFrag){
556 dbHelper.deleteList("Toast");
557 Intent i = new Intent("android.intent.action.MAIN");
558 sendBroadcast(i);
559 }
560 }
561 });
562 alertDialogBuilder.setNegativeButton("No",
563 new DialogInterface.OnClickListener() {
564 @Override
565 public void onClick(DialogInterface arg0, int arg1) {
566
567 }
568 });
569 AlertDialog alertDialog = alertDialogBuilder.create();
570 alertDialog.show();
571 }
572 });
573 BottomNavigationView bottomNavigationView = findViewById(R.id.navigation);
574
575 bottomNavigationView.setOnNavigationItemSelectedListener
576 (new BottomNavigationView.OnNavigationItemSelectedListener() {
577 @Override
578 public boolean onNavigationItemSelected(@NonNull MenuItem item) {
579 switch (item.getItemId()) {
580 case R.id.action_item1:
581 selectedFragment = NotificationFrag.newInstance();
582 break;
583 case R.id.action_item2:
584 selectedFragment = ToastFrag.newInstance();
585 break;
586 }
587 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
588 transaction.replace(R.id.frame_layout, selectedFragment);
589 transaction.commit();
590 return true;
591 }
592 });
593
594 //Manually displaying the first fragment - one time only
595 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
596 transaction.replace(R.id.frame_layout, NotificationFrag.newInstance());
597 transaction.commit();
598
599 startService(new Intent(MainActivity.this,Access.class));
600 if(!isAccessibilitySettingsOn(MainActivity.this)){
601
602 AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
603 alertDialogBuilder.setMessage("You Need to provide Accessibility Permission for this");
604 alertDialogBuilder.setPositiveButton("Ok",
605 new DialogInterface.OnClickListener() {
606 @Override
607 public void onClick(DialogInterface arg0, int arg1) {
608
609 if(!sharedPreferences.getString("isFirstRunDone", "").equals("TRUE")) {
610 editor.putString("isFirstRunDone", "TRUE");
611 editor.commit();
612 Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
613 startActivityForResult(intent, 0);
614 }
615
616 }
617 });
618 AlertDialog alertDialog = alertDialogBuilder.create();
619 alertDialog.show();
620 }
621
622
623 }
624 public boolean isAccessibilitySettingsOn(Context mContext) {
625 int accessibilityEnabled = 0;
626 final String service = getPackageName() + "/" + Access.class.getCanonicalName();
627 try {
628 accessibilityEnabled = Settings.Secure.getInt(
629 mContext.getApplicationContext().getContentResolver(),
630 android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
631 Log.v("MSG", "accessibilityEnabled = " + accessibilityEnabled);
632 } catch (Settings.SettingNotFoundException e) {
633 Log.e("MSG", "Error finding setting, default accessibility to not found: "
634 + e.getMessage());
635 }
636 TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');
637
638 if (accessibilityEnabled == 1) {
639 Log.v("MSG", "***ACCESSIBILITY IS ENABLED*** -----------------");
640 String settingValue = Settings.Secure.getString(
641 mContext.getApplicationContext().getContentResolver(),
642 Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
643 if (settingValue != null) {
644 mStringColonSplitter.setString(settingValue);
645 while (mStringColonSplitter.hasNext()) {
646 String accessibilityService = mStringColonSplitter.next();
647
648 Log.v("MSG", "-------------- > accessibilityService :: " + accessibilityService + " " + service);
649 if (accessibilityService.equalsIgnoreCase(service)) {
650 Log.v("MSG", "We've found the correct setting - accessibility is switched on!");
651 return true;
652 }
653 }
654 }
655 } else {
656 Log.v("MSG", "***ACCESSIBILITY IS DISABLED***");
657 }
658
659 return false;
660 }
661
662 @Override
663 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
664 super.onActivityResult(requestCode, resultCode, data);
665 if(requestCode == 0){
666 if(!isAccessibilitySettingsOn(MainActivity.this)){
667 drawer.closeDrawer(GravityCompat.START);
668
669 AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
670 alertDialogBuilder.setMessage("Permission Not Granted Application Wont Work");
671 alertDialogBuilder.setPositiveButton("Ok",
672 new DialogInterface.OnClickListener() {
673 @Override
674 public void onClick(DialogInterface arg0, int arg1) {
675 }
676 });
677 AlertDialog alertDialog = alertDialogBuilder.create();
678 alertDialog.show();
679
680 swService.setChecked(false);
681 if(!sharedPreferences.getString("isFirstRunDone", "").equals("TRUE")) {
682 drawer.openDrawer(GravityCompat.START);
683 }
684 }else{
685 swService.setChecked(true);
686 }
687 }
688 }
689
690 @Override
691 public boolean onNavigationItemSelected(@NonNull MenuItem item) {
692 int id = item.getItemId();
693
694 if (id == R.id.nav_service) {
695 // Handle the camera action
696
697 } else if (id == R.id.nav_delete_older) {
698 builder.create().show();
699 } else if (id == R.id.nav_delete_all) {
700
701 } else if (id == R.id.nav_share) {
702
703 } else if (id == R.id.nav_about) {
704
705 }
706
707 drawer.closeDrawer(GravityCompat.START);
708 return true;
709 }
710}