这为我工作:
,而不是导入Eclipse项目到Android的工作室,
(1)创建你已经提上了谷歌Play商店的包名称的新的Android Studio项目但使用全部小写字母。
(2)然后将所有文件复制到Android Studio项目中。 (3)将build.gradle(Module App)文件中的软件包ID改为大写的原始软件包名称(见下文)和sync(这将在apk中创建软件包名称,其中原始软件包名称用大写字符,它会上传到谷歌Play商店并更换旧的!
(4)本安装APK(大写包名)在我的测试手机,它完美地工作。
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "DrWebsterApps.New.England.Patriots.Game"
minSdkVersion 9
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.google.android.gms:play-services:7.0.0'
}
(5)作为测试用例,这里是弹出当前运行的应用程序包名称以证明它的代码:
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ListActivity;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.List;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* put this in the manifest.xml file!!!
<uses-permission android:name="android.permission.GET_TASKS"/>
*/
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
createDialogAnswer(taskInfo.get(0).topActivity.getPackageName());
}
public void createDialogAnswer(String msg) {
AlertDialog.Builder adb;
LinearLayout linear = new LinearLayout(this);
linear.setBackgroundColor(Color.RED);
linear.setOrientation(LinearLayout.VERTICAL);
adb = new AlertDialog.Builder(this);
// String team = (string)R.string.app_name;
adb.setTitle(" Trivia App");
adb.setView(linear);
LayoutInflater mInflater = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View PopUpView = mInflater.inflate(R.layout.scores, linear);
TextView mytext = (TextView) PopUpView.findViewById(R.id.QPopUp);
// mytext.setTextColor(getResources().getColor(R.color.White));
// mytext.setTextSize(getResources().getDimension(R.dimen.aboutApp_text_size));
mytext.append(msg + " \n");
adb.setNegativeButton("Quit", myDialogOnClickListener);
adb.show();
}
DialogInterface.OnClickListener myDialogOnClickListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface v, int x) {
finish();
}
};
只是为了澄清,这是我的ApplicationId,而不是清单中我的项目包名称。在Eclipse中一切正常。在添加Google服务之前,它也在Android Studio中工作。我现在坚持与Eclipse?我不相信没有解决方法来支持这一点。 –