我准备推销我的第一个Android应用程序(来自美国Google Checkout/Merchant帐户和美国银行帐户等),我想让用户在他/她之前至少同意某种简单的责任免责声明可以安装该应用程序.
据您所知,是否可能,如果可行,最好的方法是什么?
非常感谢您的帮助和提示.
Cri*_*ian 10
当你说" 在他/她可以安装应用程序之前 "我想你的意思是在允许用户安装应用程序的同一屏幕中你想要放置免责声明.好吧,我认为这是不可能的.事实上,应用程序可以以不同的方式安装(来自第三方应用程序,或通过abd install在有根的手机上使用).
所以,我的建议是将该免责声明放在主要活动中.您可以在某处保存用户决策(最简单的方法是首选).这样,您可以检查用户是否已接受免责声明.当然,如果用户不接受,你就不要让他/她使用你的应用程序.
public class MainActivity extends Activity {
public static final String PREFS_NAME = "user_conditions";
@Override
protected void onCreate(Bundle state){
super.onCreate(state);
// bla bla bla
// Check whether the user has already accepted
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean accepted = settings.getBoolean("accepted", false);
if( accepted ){
// do what ever you want... for instance:
startActivity(new Intent(this, RealApp.class));
}else{
// show disclaimer....
// for example, you can show a dialog box... and,
// if the user accept, you can execute something like this:
// We need an Editor object to make preference changes.
// All objects are from android.context.Context
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("accepted", true);
// Commit the edits!
editor.commit();
}
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我根据Cristian的例子实现Dialog的方法:
在activity类中,我创建了这个方法:
protected Dialog onCreateDialog(int id){
// show disclaimer....
// for example, you can show a dialog box...
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("LEGAL DISCLAIMER: ... ")
.setCancelable(false)
.setPositiveButton("Agree", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// and, if the user accept, you can execute something like this:
// We need an Editor object to make preference changes.
// All objects are from android.context.Context
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("accepted", true);
// Commit the edits!
editor.commit();
}
})
.setNegativeButton("Disagree", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
nm.cancel(R.notification.running); // cancel the NotificationManager (icon)
System.exit(0);
}
});
AlertDialog alert = builder.create();
return alert;
}
Run Code Online (Sandbox Code Playgroud)
在onCreate()方法的开头,我添加了以下行:
// Check whether the user has already accepted
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean accepted = settings.getBoolean("accepted", false);
if( accepted ){
// do what ever you want... for instance:
}else{
showDialog(0);
}
Run Code Online (Sandbox Code Playgroud)
干杯,克里斯
| 归档时间: |
|
| 查看次数: |
4147 次 |
| 最近记录: |