gpt4 book ai didi

android - 找不到符号变量 SEND_SMS

转载 作者:行者123 更新时间:2023-11-29 17:24:53 25 4
gpt4 key购买 nike

我正在尝试从 Android 应用程序发送短信,编写了以下代码,但出现编译错误:“找不到符号变量 SEND_SMS”。我还导入了“android.Manifest.permission”但没有解决。请帮助我。

案例 R.id.SendSMS:

            // Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.SEND_SMS)
!= PackageManager.PERMISSION_GRANTED) {

// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.SEND_SMS)) {

// Show an expanation 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.

} else {

// No explanation needed, we can request the permission.

ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.SEND_SMS},
MY_PERMISSIONS_REQUEST_SEND_SMS);

// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
try {

SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(diaryEntry.getText().toString(),
null, diaryEntry.getText().toString(),
null, null);
Toast.makeText(getApplicationContext(), "Your sms has successfully sent!",
Toast.LENGTH_LONG).show();
} catch (Exception ex) {
Toast.makeText(getApplicationContext(),"Your sms has failed...",
Toast.LENGTH_LONG).show();
ex.printStackTrace();
}


Build.gradle dependencies:



android {

compileSdkVersion 23

buildToolsVersion "23.0.1"

defaultConfig {
applicationId "amana.loginapp"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}


dependencies {

compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.android.support:support-v4:23.1.1'
}

AndroidManifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="amana.loginapp">

<!-- Send SMS permission -->
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>

最佳答案

我用这个解决了这个问题

android.Manifest.permission.SEND_SMS;

代替

Manifest.permission.SEND_SMS

关于android - 找不到符号变量 SEND_SMS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35056911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com