Итак, я просмотрел каждую страницу документа и страницу StackOverflow, чтобы найти ответ на этот вопрос, и я буквально ничего не нашел. Сегодня я делаю приложение, которое должно читать все SMS-сообщения, которые я получаю, и искать определенную фразу.
Однако я понял, что мне нужно разрешение RECEIVE_SMS, что я и сделал - отказано в разрешении.
Поэтому я добавил в приложение возможность запрашивать разрешения у пользователя, учитывая, что SDK превышает 22 - разрешение отклонено.
Я подключил каждую мелочь, которую нашел на этих форумах, и, похоже, ничего не работает, независимо от того, что я делаю, он по-прежнему говорит, что разрешение запрещено, и я не могу читать SMS-сообщения.
Если кто-то может помочь, это будет очень ценно, потому что в данный момент оно начинает казаться, что приложение потеряно.
Вот как выглядит ошибка:
2019-10-30 14:50:53.097 1403-1413/? W/BroadcastQueue: Permission Denial: receiving Intent { act=android.provider.Telephony.SMS_RECEIVED flg=0x19000010 (has extras) } to ProcessRecord{cb5e9afd0 1159:com.samsung.android.email.provider/u0a68} (pid=1159, uid=10068) requires android.permission.RECEIVE_SMS due to sender com.android.phone (uid 1001)
Вот файл MainActivity:
package app.genyie.tnat;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private static final int PERMISSIONS_REQUEST_RECEIVE_SMS = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
requestPermissions(Manifest.permission.RECEIVE_SMS, PERMISSIONS_REQUEST_RECEIVE_SMS);
}
private void requestPermissions(String permission, int requestCode) {
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(this, permission)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
Toast.makeText(this, "Granting permission is necessary!", Toast.LENGTH_LONG).show();
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{permission},
requestCode);
// requestCode is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case PERMISSIONS_REQUEST_RECEIVE_SMS: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay! Do the
// contacts-related task you need to do.
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
}
}
А вот и манифест:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="app.genyie.tnat">
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-sdk android:minSdkVersion="26"/>
<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".BGServ"/>
<receiver
android:name=".SmsListener">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
</application>
</manifest>
Если вам нужны какие-либо другие файлы, дайте мне знать, спасибо за ваше время!