我正在修改一个用于添加Marshmallow权限的android工作室项目。
我有2个java文件
Perijinan.java
public class Perijinan extends AppCompatActivity implements OnRequestPermissionsResultCallback {
private static final int PERMISSION_REQUEST_CAMERA = 0;
public static int status;
int REQUEST_CODE;
private View mLayout;
public Perijinan() {
this.REQUEST_CODE = 1;
}
static {
status = 0;
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView((int) R.layout.dialog_url);
if (VERSION.SDK_INT < 23) {
startActivity(new Intent(this, MainActivity.class));
status = 1;
} else if (checkSelfPermission("android.permission.WRITE_EXTERNAL_STORAGE") == 0) {
startActivity(new Intent(this, MainActivity.class));
status = 1;
} else {
ActivityCompat.requestPermissions(this, new String[]{"android.permission.WRITE_EXTERNAL_STORAGE"}, this.REQUEST_CODE);
}
}
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == this.REQUEST_CODE && grantResults.length == 1 && grantResults[0] == 0) {
startActivity(new Intent(this, MainActivity.class));
}
}
}
BlockGraphView.java
public class BlockGraphView extends View
{
private static int BLOCKS_PER_LINE = 15;
private int mForeground, mBackground;
private int mBlockSize, mLineCount;
private DownloadMission mMission;
public BlockGraphView(Context context) {
this(context, null);
}
public BlockGraphView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public BlockGraphView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
try {
TypedArray array = context.obtainStyledAttributes(R.styleable.Theme);
mBackground = array.getColor(R.styleable.Theme_colorPrimary, 0);
mForeground = array.getColor(R.styleable.Theme_colorPrimaryDark, 0);
array.recycle();
} catch (Exception e) {
}
}
}
我的Gradle文件如下
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "us.myapp.name"
minSdkVersion 16
targetSdkVersion 21
versionCode 8
versionName "1.1.4"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:support-v4:22.2.0'
compile 'com.google.code.gson:gson:2.3.+'
compile 'com.nononsenseapps:filepicker:2.0.5'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
这是我的问题。
如果我在gradle文件中使用编译'com.android.support:appcompat-v7:22.2.0'
并编译'com.android.support:support-v4:22.2.0'
,我在Perijinan.java中出现错误,显示错误
OnRequestPermissionsResultCallback,requestPermissions等。
可以通过将编译更改为'com.android.support:appcompat-v7:23.2.0'
和compile 'com.android.support:support-v4:23.2.0'
来解决。
但如果我使用'com.android.support:appcompat-v7:23.2.0'
和compile 'com.android.support:support-v4:23.2.0'
,我的错误
在mBackground下的BlockGraphView.java = array.getColor(R.styleable.Theme_colorPrimary,0);和mForeground = array.getColor(R.styleable.Theme_colorPrimaryDark,0); [R.styleable.Theme_colorPrimaryDark,R.styleable.Theme_colorPrimary as red marked]
我该如何解决这个问题?
答案 0 :(得分:0)
请在下面的模式中重命名您的支持库依赖项并检查,因为这可能会对您有所帮助。而不是硬编码,它会选择最新的更新。
compile&#39; com.android.support:appcompat-v7:$ supportLibraryVersion&#39; 编译&#39; com.android.support:support-v4:$ supportLibraryVersion&#39;