我正在制作一个显示已安装应用程序列表的应用程序,并在项目上单击显示权限。此外,它在后台运行并在设备启动时启动。它在 Motorola Milestone(Android 2.1)上完美运行,但在 Sony Xperia(ICS) 上进行测试时,不会单击列表,因此不会显示显示权限的活动。
LogCat 在错误模式下不显示任何内容。
主要活动
package com.example.appslist;
import java.util.List;
import com.example.appslist.adapter.ApkAdapter;
import com.example.appslist.app.AppData;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import com.example.backgroundapp.BackgroundService;
public class ApkListActivity extends Activity implements OnItemClickListener {
PackageManager packageManager;
public static boolean isService = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startService(new Intent(ApkListActivity.this,BackgroundService.class));
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
isService = true;
packageManager = getPackageManager();
List<PackageInfo> packageList = packageManager
.getInstalledPackages(PackageManager.GET_PERMISSIONS);
ListView mylistview= (ListView) findViewById(android.R.id.list);
mylistview.setAdapter(new ApkAdapter(this, packageList, packageManager));
mylistview.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long row) {
super.onResume();
stopService(new Intent(ApkListActivity.this,
BackgroundService.class));
PackageInfo packageInfo = (PackageInfo) parent
.getItemAtPosition(position);
AppData appData = (AppData) getApplication();
appData.setPackageInfo(packageInfo);
Intent appInfo = new Intent(ApkListActivity.this, ApkInfo.class);
startActivity(appInfo);
}
}
显现
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.appslist"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name=".app.AppData">
<activity
android:name="com.example.appslist.ApkListActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ApkInfo"
android:label="@string/title_activity_apk_info" >
</activity>
<service android:enabled="true" android:name=".BackgroundService" />
<receiver
android:enabled="true"
android:name="com.example.appslist.BootUpReceiver"
>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
``</receiver>
</application>
</manifest>
请帮忙