Created
September 19, 2013 03:30
-
-
Save myamamic/6618773 to your computer and use it in GitHub Desktop.
[android][java] JavaScriptで実装したGPS位置情報取得の許可ダイアログ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.webkit.GeolocationPermissions.Callback; | |
private WebChromeClient mWebChromeClient = new WebChromeClient() { | |
/** | |
* JavaScriptからの位置情報取得を許可する | |
* ユーザーに位置情報取得するかどうかの確認ダイアログは表示しないパターン | |
*/ | |
@TargetApi(Build.VERSION_CODES.ECLAIR) | |
@Override | |
public void onGeolocationPermissionsShowPrompt(final String origin, | |
final Callback callback) { | |
super.onGeolocationPermissionsShowPrompt(origin, callback); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) { | |
callback.invoke(origin, true, false); | |
} | |
} | |
/** | |
* JavaScriptからの位置情報取得を許可する | |
* ユーザーに位置情報取得するかどうかの確認ダイアログを表示するパターン | |
*/ | |
@TargetApi(Build.VERSION_CODES.ECLAIR) | |
@Override | |
public void onGeolocationPermissionsShowPrompt(final String origin, | |
final Callback callback) { | |
super.onGeolocationPermissionsShowPrompt(origin, callback); | |
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); | |
builder.setIcon(R.drawable.ic_launcher); | |
builder.setTitle(R.string.app_name); | |
builder.setMessage(R.string.ask_location); | |
builder.setPositiveButton(R.string.agree, new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int which) { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) { | |
callback.invoke(origin, true, false); | |
} | |
} | |
}); | |
builder.setNegativeButton(R.string.disagree, new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int which) { | |
// 拒否された場合は、何もしない | |
} | |
}); | |
builder.show(); | |
} | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 位置情報取得許可を求めるダイアログのリソース --> | |
<string name="ask_location">This application wants to use your location.</string> | |
<string name="agree">Share location</string> | |
<string name="disagree">Disagree</string> | |
<!-- 位置情報取得許可を求めるダイアログのリソース --> | |
<string name="ask_location">アプリケーションは位置情報を要求しています。許可しますか?</string> | |
<string name="agree">許可する</string> | |
<string name="disagree">許可しない</string> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment