Advertisement
Guest User

Untitled

a guest
May 26th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.33 KB | None | 0 0
  1. 5-25 11:07:15.346 2459-2493/com.example.prakaash.knowyourlocation W/MessageQueue: Handler (android.location.LocationManager$ListenerTransport$1) {7743340} sending message to a Handler on a dead thread
  2. java.lang.IllegalStateException: Handler (android.location.LocationManager$ListenerTransport$1) {7743340} sending message to a Handler on a dead thread
  3. at android.os.MessageQueue.enqueueMessage(MessageQueue.java:545)
  4. at android.os.Handler.enqueueMessage(Handler.java:662)
  5. at android.os.Handler.sendMessageAtTime(Handler.java:631)
  6. at android.os.Handler.sendMessageDelayed(Handler.java:601)
  7. at android.os.Handler.sendMessage(Handler.java:538)
  8. at android.location.LocationManager$ListenerTransport.onLocationChanged(LocationManager.java:255)
  9. at android.location.ILocationListener$Stub.onTransact(ILocationListener.java:58)
  10. at android.os.Binder.execTransact(Binder.java:697)
  11.  
  12. java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=100, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.example.prakaash.myapplication/com.example.prakaash.myapplication.MainActivity}: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.example.prakaash.myapplication.ServiceClass (has extras) }
  13. at android.app.ActivityThread.deliverResults(ActivityThread.java:4268)
  14. at android.app.ActivityThread.handleSendResult(ActivityThread.java:4312)
  15. at android.app.ActivityThread.-wrap19(Unknown Source:0)
  16. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1644)
  17. at android.os.Handler.dispatchMessage(Handler.java:106)
  18. at android.os.Looper.loop(Looper.java:164)
  19. at android.app.ActivityThread.main(ActivityThread.java:6494)
  20. at java.lang.reflect.Method.invoke(Native Method)
  21. at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
  22. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
  23. Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.example.prakaash.myapplication.ServiceClass (has extras) }
  24. at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1464)
  25. at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1505)
  26. at android.app.ContextImpl.startService(ContextImpl.java:1477)
  27. at android.content.ContextWrapper.startService(ContextWrapper.java:650)
  28. at com.example.prakaash.myapplication.MainActivity.onRequestPermissionsResult(MainActivity.java:42)
  29. at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7429)
  30. at android.app.Activity.dispatchActivityResult(Activity.java:7280)
  31. at android.app.ActivityThread.deliverResults(ActivityThread.java:4264)
  32. at android.app.ActivityThread.handleSendResult(ActivityThread.java:4312)
  33. at android.app.ActivityThread.-wrap19(Unknown Source:0)
  34. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1644)
  35. at android.os.Handler.dispatchMessage(Handler.java:106)
  36. at android.os.Looper.loop(Looper.java:164)
  37. at android.app.ActivityThread.main(ActivityThread.java:6494)
  38. at java.lang.reflect.Method.invoke(Native Method)
  39. at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
  40. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
  41.  
  42. String phone="9940262305";
  43. @Override
  44. protected void onCreate(Bundle savedInstanceState)
  45. {
  46. super.onCreate(savedInstanceState);
  47. setContentView(R.layout.activity_main);
  48. runtime_permissions();
  49. }
  50.  
  51. private boolean runtime_permissions() {
  52. if(Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED){
  53.  
  54. requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.READ_PHONE_STATE, Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.SEND_SMS,Manifest.permission.RECEIVE_SMS},100);
  55.  
  56. return true;
  57. }
  58. return false;
  59. }
  60.  
  61.  
  62. @Override
  63. public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
  64. super.onRequestPermissionsResult(requestCode, permissions, grantResults);
  65. if(requestCode == 100){
  66. if( grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED){
  67. RecieverClass recieverClass=new RecieverClass();
  68. Intent serviceIntent = new Intent(ServiceClass.class.getName());
  69. serviceIntent.putExtra("UserID", phone);
  70. startService(serviceIntent);
  71. }else {
  72. runtime_permissions();
  73. }
  74. }
  75. }
  76.  
  77. int count=1;
  78.  
  79. @Override
  80. public void onReceive(Context context, Intent intent) {
  81. final Bundle bundle = intent.getExtras();
  82.  
  83. try {
  84.  
  85. if (bundle != null)
  86. {
  87.  
  88. final Object[] pdusObj = (Object[]) bundle.get("pdus");
  89.  
  90. for (int i = 0; i < pdusObj.length; i++)
  91. {
  92.  
  93. SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
  94. String phoneNumber = currentMessage.getDisplayOriginatingAddress();
  95.  
  96. String senderNum = phoneNumber;
  97. String message = currentMessage.getDisplayMessageBody();
  98.  
  99. if(message.contains("Trace"))
  100. {
  101. Toast.makeText(context, "Working", Toast.LENGTH_SHORT).show();
  102. Intent service =new Intent(context,ServiceClass.class);
  103. context.startService(service);
  104. }
  105.  
  106. } // end for loop
  107.  
  108. } // bundle is null
  109.  
  110. }
  111. catch (Exception e)
  112.  
  113. {
  114. Log.e("SmsReceiver", "Exception smsReceiver" +e);
  115. }
  116. }
  117.  
  118. LocationListener listener;
  119. LocationManager locationManager;
  120. int count=1;
  121. String number;
  122.  
  123. public ServiceClass() {
  124. super("Location");
  125. }
  126.  
  127.  
  128.  
  129. @SuppressLint("MissingPermission")
  130. @Override
  131. protected void onHandleIntent(@Nullable Intent intent) {
  132. listener = new LocationListener() {
  133.  
  134. @Override
  135. public void onLocationChanged(Location location) {
  136.  
  137. String locat=String.valueOf(location.getLatitude() + "," + location.getLongitude());
  138. if(count==1 )
  139. {
  140.  
  141.  
  142. SmsManager sms = SmsManager.getDefault();
  143. if(number !=null)
  144. {
  145. sms.sendTextMessage(number, null, "Know where they are " + "https://www.google.com/maps/?q=" + locat, null, null);
  146. count++;
  147. }
  148. else
  149. {
  150. Toast.makeText(ServiceClass.this, "number is null", Toast.LENGTH_SHORT).show();
  151. }
  152. }
  153. }
  154.  
  155. @Override
  156. public void onStatusChanged(String s, int i, Bundle bundle) {
  157.  
  158. }
  159.  
  160. @Override
  161. public void onProviderEnabled(String s) {
  162.  
  163. }
  164.  
  165. @Override
  166. public void onProviderDisabled(String s) {
  167. Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
  168. i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  169. startActivity(i);
  170. }
  171. };
  172.  
  173. locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
  174. //noinspection MissingPermission
  175. locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,3000,0,listener);
  176.  
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement