gpt4 book ai didi

java - 在 DialogFragment 中使用 getIntent() 和 getPackageInfo

转载 作者:行者123 更新时间:2023-12-01 18:39:57 24 4
gpt4 key购买 nike

我正在创建一个对话框,显示特定应用程序所需的权限。问题是我无法在不扩展Activity的类中使用getIntent()和getPackageInfo,那么我该怎么办?代码是这样的。

public class DialogPermissions extends DialogFragment{

public android.app.Dialog onCreateDialog(Bundle savedInstanceState) {

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
String value2;
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.dialog_permissions, null);
builder.setView(view);

TextView permissions = (TextView)view.findViewById(R.id.permissions);

Bundle extras = getIntent().getExtras();
if(extras!=null) {
value2 = getIntent().getStringExtra("packageApplication");
}

try {
PackageInfo packageInfo = getPackageInfo(value2, PackageManager.GET_PERMISSIONS);

String[] requestedPermissions = packageInfo.requestedPermissions;
if ( requestedPermissions != null ) {
for (int i = 0; i < requestedPermissions.length; i++) {
}

}
}
catch ( PackageManager.NameNotFoundException e ) {
e.printStackTrace();
}

builder.setTitle("Permission")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dismiss();
}
});

return builder.create();
}
}

最佳答案

你可以这样使用它-

Intent i = getActivity().getIntent();

和-

getActivity().getPackageManager().getPackageInfo(packageName, flags)

关于java - 在 DialogFragment 中使用 getIntent() 和 getPackageInfo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20360920/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com