我有一个列表活动,显示设备中所有正在运行的应用程序.它显示所有应用程序的默认图标.但我需要为列表中的每个应用程序获取实际应用程序图标.
public class ApplicationList extends ListActivity {
DataHelper dh;
ImageView vi;
private Drawable icon;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.applist);
dh = new DataHelper(getApplicationContext());
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
Log.d("Test1", "INSERTING APP LIST TO SERVER DB");
List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
ArrayList<String> applist = new ArrayList<String>();
for(ResolveInfo rInfo: list){
applist.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString() );
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.installedapp, R.id.textView1, applist);
setListAdapter(adapter);
}
Run Code Online (Sandbox Code Playgroud)
如何获取其他应用程序的图标(Android) 我尝试了这个链接,但我没有解决问题.所以任何人都可以帮助我.谢谢!
活动显示带有正按钮的对话窗口.点击按钮,它将进入Staticdisplay活动.我正在尝试在加载活动时添加进度条.我收到以下错误.$BadTokenException: Unable to add window -- token null is not for an application
这是添加进程栏的代码.. progressBar.show();我在这一行得到错误.我该如何摆脱这个错误.谢谢.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCustomTitle(title);
builder.setMessage(R.string.app_description).setPositiveButton(
"Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (Registration.isRunning == false) {
startService(new Intent(
getApplicationContext(),
Registration.class));
}
staticInfo();
if (Registration.ruid == null)
Registration.ruid = uId;
progressBar = new ProgressDialog(
getApplicationContext());
progressBar.setCancelable(true);
progressBar.setMessage("Loading Activity...");
progressBar
.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressBar.setProgress(0);
progressBar.setMax(100);
progressBar.show();
progressBarStatus = 0;
new Thread(new Runnable() {
public void run() {
while …Run Code Online (Sandbox Code Playgroud) 有没有机会将TELEPHONY_SERVICE作为null?
TelephonyManager teleman = (TelephonyManager) getBaseContext()
.getSystemService(Context.TELEPHONY_SERVICE);
Run Code Online (Sandbox Code Playgroud)
我的意思是在上面的行中有没有机会让teleman成为null?
在此先感谢您的回复.