我正在使用以下代码,但是当我运行它时,它“意外停止”
我已授予以下权限
<uses-permission android:name="android.permission.RESTART_PACKAGES" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.GET_PACKAGE_SIZE" />
这段代码有什么问题:
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity
{
public static String Tag = "Task";
Context ctx;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//Intent service = new Intent(this,MyService.class);
PackageManager pm = getApplicationContext().getPackageManager();
List<ApplicationInfo> pis = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
for (ApplicationInfo appinfo : pis)
{
String S1=appinfo.className.toString();
Log.i(Tag,S1);
}
}
}
我正在尝试一一检索已安装的应用程序。