Reputation: 11
I have no clue how to solve this issue.
When I try to compile the folder to APK file, there is message that says
MainActivity.java uses or overrides a deprecated API.
I am using Android Studio version 3.2.0 and Java version 8. I tried everything but it doesn't work. I also searched up internet but I couldn't get the answer.
package com.kakao.talk.theme.apeach;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
public class MainActivity extends Activity {
private static final String KAKAOTALK_SETTINGS_THEME_URI =
"kakaotalk://settings/theme/";
private static final String MARKET_URI = "market://details?id=";
private static final String KAKAO_TALK_PACKAGE_NAME = "com.kakao.talk";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
try {
Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(getResources().getColor(R.color.statusBarColor));
} catch (Throwable ignored) {
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
try {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} catch (Throwable ignored) {
}
}
final Button applyButton = (Button) findViewById(R.id.apply);
applyButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(KAKAOTALK_SETTINGS_THEME_URI + getPackageName()));
startActivity(intent);
finish();
}
});
final Button installButton = (Button) findViewById(R.id.market);
installButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(MARKET_URI + KAKAO_TALK_PACKAGE_NAME));
startActivity(intent);
finish();
}
});
try {
getPackageManager().getPackageInfo(KAKAO_TALK_PACKAGE_NAME, 0);
applyButton.setVisibility(View.VISIBLE);
installButton.setVisibility(View.GONE);
} catch (NameNotFoundException e) {
applyButton.setVisibility(View.GONE);
installButton.setVisibility(View.VISIBLE);
}
}
}
Upvotes: 1
Views: 4496
Reputation: 915
welcome to StackOverflow!
In your code, after the version check, you are trying to set the window status color by using getResources().getColor()
, which has been deprecated for a few years now.
You can use the ContextCompat to achieve this: ContextCompat.getColor(context, R.color.color_name)
.
You should change R.color.color_name
for your desired resource (in your case should be R.color.statusBarColor
) as well as pass the correct context (which should be getApplicationContext()
).
Further information can be found on this post, and never forget the great google's documentation on Android.
Upvotes: 2