Skip to content

Instantly share code, notes, and snippets.

@Yosuke-Kawakami
Created January 18, 2016 05:16
Show Gist options
  • Save Yosuke-Kawakami/e34af10cac62d640585f to your computer and use it in GitHub Desktop.
Save Yosuke-Kawakami/e34af10cac62d640585f to your computer and use it in GitHub Desktop.
アプリケーションの設定画面まで誘導するダイアログ
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v4.app.DialogFragment;
/**
* Created by y-kawakami on 2016/01/18.
* こんな感じで呼び出す
*
* if( hasInvalidData )
* new NeedToClearAppData()
* .show(getFragmentManager(), "NeedToClearAppData");
*/
public class NeedToClearAppData extends DialogFragment
{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
String message =
"アプリケーションのデータをクリアして再試行してください。\n\n"
+ "引き続きこのメッセージが出力される場合は、アプリケーションの制作元までご連絡ください";
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
.setCancelable(false)
.setTitle("xxxx の失敗")
.setMessage(message)
.setPositiveButton(
"OK",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
getActivity().finish();
Intent i = new Intent();
i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
i.setData(Uri.parse("package:" + getActivity().getPackageName()));
startActivity(i);
}
}
);
AlertDialog dialog = builder.create();
return dialog;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment