|
|
|
App android ตรวจสอบ sms แล้ว redirect ไปที่ url ไม่ทำงานครับ ไม่ทราบว่าโค๊ดผิดตรงไหนครับ |
|
|
|
|
|
|
|
MainActivity.java
package com.jawad.smsapp;
import android.Manifest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.karumi.dexter.Dexter;
import com.karumi.dexter.DexterBuilder;
import com.karumi.dexter.MultiplePermissionsReport;
import com.karumi.dexter.PermissionToken;
import com.karumi.dexter.listener.PermissionDeniedResponse;
import com.karumi.dexter.listener.PermissionGrantedResponse;
import com.karumi.dexter.listener.PermissionRequest;
import com.karumi.dexter.listener.multi.MultiplePermissionsListener;
import com.karumi.dexter.listener.single.PermissionListener;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MainActivity extends AppCompatActivity {
String TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Dexter.withActivity(this)
.withPermissions(Manifest.permission.INTERNET,
Manifest.permission.READ_SMS,
Manifest.permission.RECEIVE_SMS)
.withListener(new MultiplePermissionsListener() {
@Override
public void onPermissionsChecked(MultiplePermissionsReport report) {
Toast.makeText(MainActivity.this,"Permission Granted ",Toast.LENGTH_LONG).show();
}
@Override
public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) {
}
}).check();
}
}
Sms.java
package com.jawad.smsapp;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.provider.Telephony;
import android.support.annotation.RequiresApi;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
public class Sms extends BroadcastReceiver{
private String TAG = Sms.class.getSimpleName();
@Override
public void onReceive(Context context, Intent intent) {
try {
Log.d(TAG, "onReceive: ");
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
String messag = new String();
String sender = new String();
SmsMessage[] smsMessages = new SmsMessage[0];
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
smsMessages = Telephony.Sms.Intents.getMessagesFromIntent(intent);
}
if (smsMessages == null) {
Toast.makeText(context, "Smsmessages empty", Toast.LENGTH_LONG).show();
return;
}
for (SmsMessage message : smsMessages) {
messag = message.getDisplayMessageBody();
sender = message.getDisplayOriginatingAddress();
Log.d(TAG, "onReceive: " + message.getDisplayMessageBody());
Log.d(TAG, "onReceive: " + message.getDisplayOriginatingAddress());
}
String url = "https://www.example.com/test.php?details=" + messag + "&sender=" + sender;
Intent intent1 = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
Log.d(TAG, "onReceive: " + intent1.resolveActivity(context.getPackageManager()));
if (intent1.resolveActivity(context.getPackageManager()) != null) {
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent1);
}
}}catch(Exception e)
{
Toast.makeText(context,e.toString(),Toast.LENGTH_LONG).show();
}
}
}
Tag : Mobile
|
|
|
|
|
|
Date :
2018-10-26 09:12:40 |
By :
peap |
View :
896 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|