因此,我正在将一个运行良好的项目(在4部手机上测试)从Eclipse导入到Android工作室,当我在不修改任何内容的情况下运行该应用程序时,它根本不允许我使用互联网。
至于代码。。。发布任何代码都是毫无意义的,因为我创建了一个只连接到数据库的应用程序,但它仍然无法工作,而当我将应用程序从Eclipse运行到手机时,完全相同的代码将完美工作。(顺便说一句,是同一部手机)
只是为了确保这不会是一个答案:我在清单中添加了权限。
有什么建议吗?
//清单。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="vlad.tests.com.udptextconnection" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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>
//Build.gradle(模块:应用程序)
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "vlad.tests.com.udptextconnection"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
}
//Build.gradle(项目[项目名称])
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
尝试将权限放在应用程序标记之外。
不确定它是否有效,但请尝试清理您的项目。转到"构建"->"清理项目"。尝试"构建"->"重建项目"。