我必须在安装应用程序时解锁我的应用程序的功能(对用户) (应用程序链接出现在我的应用程序中;单击按钮时,应用程序的游戏商店链接将打开)。
注意: - 之前不应将应用程序安装在手机中。如果已安装用户,则必须要求卸载该应用程序。仅在用户卸载时 应用程序,Playstore链接应该可用。
我试过这段代码,但是有问题。问题是 - 如果用户点击按钮(即链接),无论他/她是否安装了应用程序,FEATURE都会被解锁。
TextView tv, tvad;
Button bcheck;
int p=0;
String x="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
boolean installed = appInstalledOrNot("com.ankushkapoor2015.kiittimetable");
tv = (TextView) findViewById(R.id.tvCheck);
tvad = (TextView) findViewById(R.id.tvad);
bcheck = (Button) findViewById(R.id.button);
try
{
SharedPreferences sharedPreferences = getSharedPreferences("MyData", Context.MODE_PRIVATE);
x = sharedPreferences.getString("CHECK", "");
System.out.println("FILE READ");
}
catch (Exception e)
{
System.out.println("FILE NOT READ");
}
System.out.println(x + " Hello");
if(x.equalsIgnoreCase("Installed"))
tvad.setText("UNLOCK THE FEATURE");
else
tvad.setText("LOCK THE FEATURE");
if(installed) {
tv.setText("Installed - Uninstall App"+p);
bcheck.setVisibility(View.INVISIBLE);
System.out.println("App is already installed on your phone");
} else {
tv.setText("Not Installed "+p);
System.out.println("App is not currently installed on your phone");
}
bcheck.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
p=1;//app installed
try {
SharedPreferences sharedPreferences = getSharedPreferences("MyData", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
String s = "Installed";
editor.putString("CHECK", s);
editor.commit();
System.out.println("FILE CREATED");
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.ankushkapoor2015.kiittimetable"));
startActivity(browserIntent);
}
catch (Exception e)
{
System.out.println("FILE NOT CREATED");
}
}
});
}
private boolean appInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
boolean app_installed;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
}
catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
答案 0 :(得分:0)
在if else working
中添加以下语句if(x.equalsIgnoreCase("Installed")&&installed==true)//installed==true added
tvad.setText("UNLOCK THE FEATURE");
else
tvad.setText("LOCK THE FEATURE");