Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- java.lang.IllegalStateException: Handler (android.location.LocationManager$ListenerTransport$1) {7743340} sending message to a Handler on a dead thread
- at android.os.MessageQueue.enqueueMessage(MessageQueue.java:545)
- at android.os.Handler.enqueueMessage(Handler.java:662)
- at android.os.Handler.sendMessageAtTime(Handler.java:631)
- at android.os.Handler.sendMessageDelayed(Handler.java:601)
- at android.os.Handler.sendMessage(Handler.java:538)
- at android.location.LocationManager$ListenerTransport.onLocationChanged(LocationManager.java:255)
- at android.location.ILocationListener$Stub.onTransact(ILocationListener.java:58)
- at android.os.Binder.execTransact(Binder.java:697)
- 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) }
- at android.app.ActivityThread.deliverResults(ActivityThread.java:4268)
- at android.app.ActivityThread.handleSendResult(ActivityThread.java:4312)
- at android.app.ActivityThread.-wrap19(Unknown Source:0)
- at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1644)
- at android.os.Handler.dispatchMessage(Handler.java:106)
- at android.os.Looper.loop(Looper.java:164)
- at android.app.ActivityThread.main(ActivityThread.java:6494)
- at java.lang.reflect.Method.invoke(Native Method)
- at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
- Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.example.prakaash.myapplication.ServiceClass (has extras) }
- at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1464)
- at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1505)
- at android.app.ContextImpl.startService(ContextImpl.java:1477)
- at android.content.ContextWrapper.startService(ContextWrapper.java:650)
- at com.example.prakaash.myapplication.MainActivity.onRequestPermissionsResult(MainActivity.java:42)
- at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7429)
- at android.app.Activity.dispatchActivityResult(Activity.java:7280)
- at android.app.ActivityThread.deliverResults(ActivityThread.java:4264)
- at android.app.ActivityThread.handleSendResult(ActivityThread.java:4312)
- at android.app.ActivityThread.-wrap19(Unknown Source:0)
- at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1644)
- at android.os.Handler.dispatchMessage(Handler.java:106)
- at android.os.Looper.loop(Looper.java:164)
- at android.app.ActivityThread.main(ActivityThread.java:6494)
- at java.lang.reflect.Method.invoke(Native Method)
- at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
- String phone="9940262305";
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- runtime_permissions();
- }
- private boolean runtime_permissions() {
- 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){
- 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);
- return true;
- }
- return false;
- }
- @Override
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
- super.onRequestPermissionsResult(requestCode, permissions, grantResults);
- if(requestCode == 100){
- if( grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED){
- RecieverClass recieverClass=new RecieverClass();
- Intent serviceIntent = new Intent(ServiceClass.class.getName());
- serviceIntent.putExtra("UserID", phone);
- startService(serviceIntent);
- }else {
- runtime_permissions();
- }
- }
- }
- int count=1;
- @Override
- public void onReceive(Context context, Intent intent) {
- final Bundle bundle = intent.getExtras();
- try {
- if (bundle != null)
- {
- final Object[] pdusObj = (Object[]) bundle.get("pdus");
- for (int i = 0; i < pdusObj.length; i++)
- {
- SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
- String phoneNumber = currentMessage.getDisplayOriginatingAddress();
- String senderNum = phoneNumber;
- String message = currentMessage.getDisplayMessageBody();
- if(message.contains("Trace"))
- {
- Toast.makeText(context, "Working", Toast.LENGTH_SHORT).show();
- Intent service =new Intent(context,ServiceClass.class);
- context.startService(service);
- }
- } // end for loop
- } // bundle is null
- }
- catch (Exception e)
- {
- Log.e("SmsReceiver", "Exception smsReceiver" +e);
- }
- }
- LocationListener listener;
- LocationManager locationManager;
- int count=1;
- String number;
- public ServiceClass() {
- super("Location");
- }
- @SuppressLint("MissingPermission")
- @Override
- protected void onHandleIntent(@Nullable Intent intent) {
- listener = new LocationListener() {
- @Override
- public void onLocationChanged(Location location) {
- String locat=String.valueOf(location.getLatitude() + "," + location.getLongitude());
- if(count==1 )
- {
- SmsManager sms = SmsManager.getDefault();
- if(number !=null)
- {
- sms.sendTextMessage(number, null, "Know where they are " + "https://www.google.com/maps/?q=" + locat, null, null);
- count++;
- }
- else
- {
- Toast.makeText(ServiceClass.this, "number is null", Toast.LENGTH_SHORT).show();
- }
- }
- }
- @Override
- public void onStatusChanged(String s, int i, Bundle bundle) {
- }
- @Override
- public void onProviderEnabled(String s) {
- }
- @Override
- public void onProviderDisabled(String s) {
- Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
- i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(i);
- }
- };
- locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
- //noinspection MissingPermission
- locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,3000,0,listener);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement