[英]Is Android license agreement the same as Android SDK license agreement?
[英]show a license agreement in android application
當用戶第一次使用應用程序時,我們必須顯示許可協議對話框,現在我有兩個問題:
1這個對話框放在哪里?
添加另一個活動或將對話框放在MainActivity
(啟動活動)?
2如果用戶點擊“拒絕”,如何關閉應用程序
一旦用戶點擊“拒絕”按鈕,這意味着他/她不同意我們的許可,那么我們必須完全退出該應用程序。 怎么做?
根據“Ahmad”的回答,我將決定是否在活動開始時打開一個對話框( onCreate
方法):
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
this.setupLicense();
this.setupViews();
this.initSomeJob();
}
private void setupLicense() {
SharedPreferences setting = getSharedPreferences(IConstant.Map_License, 0);
boolean mapLicenseAccept = setting.getBoolean(IConstant.Map_License, false);
if (!mapLicenseAccept) {
//user does not accept the license yet, we will open the dialog
showDialog(Dialog_Map_License);
}
}
@Override
protected Dialog onCreateDialog(int id) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
switch (id) {
case Dialog_Map_License:
builder.setIconAttribute(android.R.attr.alertDialogIcon)
.setTitle(R.string.map_license_title)
.setMessage(R.string.map_license_content)
.setPositiveButton(R.string.map_license_accept, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//License accepted, persisted it.
SharedPreferences settings = getSharedPreferences(IConstant.Map_License, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean(IConstant.Map_License, true);
editor.commit();
}
})
.setNegativeButton(R.string.map_license_reject, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//do nothing and exit
Process.killProcess(Process.myPid());
System.exit(0);
}
});
Dialog target = builder.create();
target.setCanceledOnTouchOutside(false);
return target;
}
return null;
}
但現在我遇到了兩個問題:
1事件我選擇“接受”按鈕,第二次打開我的應用程序后,對話框將顯示。
似乎以下代碼不起作用:
editor.putBoolean(IConstant.Map_License, true);
editor.commit();
2當我顯示對話框時,代碼:
this.setupViews();
this.initSomeJob();
仍然會運行,它們不會被阻止,因為在用戶點擊“接受”按鈕之前不應該執行任何操作。
有什么想法解決它嗎?
這個對話框放在哪里?
當用戶第一次打開應用程序時,就在開頭。 如果已經顯示此對話框,則通過將其保存在共享首選項中來跟蹤它。 您不必為此創建單獨的活動。 你可以,但我見過的大多數應用都沒有。
如果用戶點擊“拒絕”,如何關閉應用程序
只需完成活動,並將其保存在您的共享首選項中。 因此,每次用戶打開您的應用程序時,您都會檢查“hasUserAcceptedOurAgreement”的布爾值是否為真,然后根據該值繼續。
我只是從技術角度回答如何可靠地完成這項工作。 我不是律師,但據我所知,將許可協議提交給Play商店是完全有效的,因此可以從應用程序應用程序頁面獲取( 為什么還有這個選項? )。
onCreateDialog已被棄用。 請改用對話框片段。 優點是顯示對話框的代碼將從活動中移出,然后您可以從任何活動顯示對話框。 也動了
SharedPreferences setting = getSharedPreferences(IConstant.Map_License, 0);
boolean mapLicenseAccept = setting.getBoolean(IConstant.Map_License, false);
像isLicenceAccepted這樣的實用方法,類似地用於存儲數據
SharedPreferences settings = getSharedPreferences(IConstant.Map_License, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean(IConstant.Map_License, true);
editor.commit();
在實用程序中像acceptLicence這樣的方法。 您可以在此處找到如何在對話框Fragment和您的活動之間進行通信。 在您的界面而不是onArticleSelected
您將必須實現兩個onLicence接受和onLicenceRejected方法。 在您的活動中實現接口覆蓋這兩個方法並采取適當的操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.