mirror of
https://github.com/tijder/SmsMatrix.git
synced 2024-10-27 18:24:01 +00:00
parent
fd21cf0b5b
commit
762cb97000
@ -26,6 +26,8 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation 'com.android.support:appcompat-v7:26.0.0'
|
||||||
|
|
||||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
|
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
|
||||||
exclude group: 'com.android.support', module: 'support-annotations'
|
exclude group: 'com.android.support', module: 'support-annotations'
|
||||||
|
@ -12,6 +12,15 @@ import android.view.View;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
import android.support.v4.app.ActivityCompat;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
|
||||||
|
import static android.Manifest.permission.READ_CONTACTS;
|
||||||
|
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
|
||||||
|
import static android.Manifest.permission.READ_PHONE_STATE;
|
||||||
|
import static android.Manifest.permission.READ_SMS;
|
||||||
|
import static android.Manifest.permission.RECEIVE_SMS;
|
||||||
|
import static android.Manifest.permission.SEND_SMS;
|
||||||
import static android.content.ContentValues.TAG;
|
import static android.content.ContentValues.TAG;
|
||||||
|
|
||||||
public class MainActivity extends Activity {
|
public class MainActivity extends Activity {
|
||||||
@ -24,12 +33,15 @@ public class MainActivity extends Activity {
|
|||||||
private EditText hsUrl;
|
private EditText hsUrl;
|
||||||
private EditText syncDelay;
|
private EditText syncDelay;
|
||||||
private EditText syncTimeout;
|
private EditText syncTimeout;
|
||||||
|
private static final String[] PERMISSIONS_REQUIRED = new String[]{
|
||||||
|
READ_SMS, SEND_SMS, RECEIVE_SMS, READ_PHONE_STATE, READ_CONTACTS, READ_EXTERNAL_STORAGE
|
||||||
|
};
|
||||||
|
private static final int PERMISSION_REQUEST_CODE = 200;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
checkPermissions();
|
|
||||||
|
|
||||||
sp = getSharedPreferences("settings", Context.MODE_PRIVATE);
|
sp = getSharedPreferences("settings", Context.MODE_PRIVATE);
|
||||||
botUsername = (EditText) findViewById(R.id.editText_botUsername);
|
botUsername = (EditText) findViewById(R.id.editText_botUsername);
|
||||||
@ -53,7 +65,9 @@ public class MainActivity extends Activity {
|
|||||||
saveButton.setOnClickListener(new View.OnClickListener() {
|
saveButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
checkPermissions();
|
if (!checkPermissions()) {
|
||||||
|
askPermissions();
|
||||||
|
} else {
|
||||||
SharedPreferences.Editor editor = sp.edit();
|
SharedPreferences.Editor editor = sp.edit();
|
||||||
editor.putString("botUsername", botUsername.getText().toString());
|
editor.putString("botUsername", botUsername.getText().toString());
|
||||||
editor.putString("botPassword", botPassword.getText().toString());
|
editor.putString("botPassword", botPassword.getText().toString());
|
||||||
@ -67,25 +81,31 @@ public class MainActivity extends Activity {
|
|||||||
Log.e(TAG, "onClick: " + botUsername.getText().toString() );
|
Log.e(TAG, "onClick: " + botUsername.getText().toString() );
|
||||||
startService();
|
startService();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
if (!checkPermissions()) {
|
||||||
|
askPermissions();
|
||||||
|
} else {
|
||||||
startService();
|
startService();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkPermissions() {
|
|
||||||
askPermission(Manifest.permission.READ_SMS);
|
|
||||||
askPermission(Manifest.permission.SEND_SMS);
|
|
||||||
askPermission(Manifest.permission.RECEIVE_SMS);
|
|
||||||
askPermission(Manifest.permission.READ_PHONE_STATE);
|
|
||||||
askPermission(Manifest.permission.READ_CONTACTS);
|
|
||||||
askPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void askPermission(String permission) {
|
private boolean checkPermissions() {
|
||||||
if (getApplicationContext().checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
|
for (String permission: PERMISSIONS_REQUIRED) {
|
||||||
this.requestPermissions(new String[]{permission},1);
|
int result = ContextCompat.checkSelfPermission(getApplicationContext(), permission);
|
||||||
|
if (result != PackageManager.PERMISSION_GRANTED) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
Log.i(TAG, "setOnClickListener - result result result" + result);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void askPermissions() {
|
||||||
|
ActivityCompat.requestPermissions(this, PERMISSIONS_REQUIRED, PERMISSION_REQUEST_CODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void startService() {
|
private void startService() {
|
||||||
Intent intent = new Intent(this, MatrixService.class);
|
Intent intent = new Intent(this, MatrixService.class);
|
||||||
|
Loading…
Reference in New Issue
Block a user