Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added: 增加获取应用label和包名的对应关系 #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ buildscript {
dependencies {
// Android plugin for gradle
// http://google.github.io/android-gradle-dsl
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Jul 06 10:31:50 CST 2017
#Tue Dec 05 15:39:40 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.11-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
4 changes: 2 additions & 2 deletions keyboardservice/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId 'com.android.adbkeyboard'
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.1"
versionCode 3
versionName "2.1"
}
}

Expand Down
15 changes: 12 additions & 3 deletions keyboardservice/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.adbkeyboard"
android:versionCode="1"
android:versionName="1.0" >
android:versionCode="2"
android:versionName="2.0" >

<uses-sdk
android:minSdkVersion="8"
Expand Down Expand Up @@ -29,7 +29,16 @@
<action android:name="android.view.InputMethod" />
</intent-filter>
<meta-data android:name="android.view.im" android:resource="@xml/methods" />
</service>
</service>

<service
android:name=".ProcessInfoService"
android:exported="true">
<intent-filter>
<action android:name="com.android.adbkeyboard.ProcessInfo"/>
</intent-filter>
</service>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.android.adbkeyboard;

/**
* Created by andrewleo on 2017/11/1.
*/

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

import android.app.IntentService;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONObject;

public class ProcessInfoService extends IntentService {

private static final String PROCESS_INFO_ACTION = "com.android.adbkeyboard.ProcessInfo";
private static final String DEFAULT_FILE_PATH = "/data/local/tmp/appinfos";

public ProcessInfoService() {
super("ProcessInfoService");
}

@Override
protected void onHandleIntent(Intent intent) {
if (intent != null) {
Bundle bundle = intent.getExtras();
String fileToSaved = (bundle != null) ? bundle.getString("fileToSave",
DEFAULT_FILE_PATH) : DEFAULT_FILE_PATH;
try {
switch (intent.getAction()) {
case PROCESS_INFO_ACTION:
JSONArray jsonArray = new JSONArray();
PackageManager pm = this.getPackageManager();
for (ApplicationInfo appinfo : getAppInfos()) {
JSONObject jsonObject = new JSONObject();
jsonObject.put(appinfo.loadLabel(pm).toString(), appinfo.processName);
jsonArray.put(jsonObject);
}
saveToFile(fileToSaved, jsonArray.toString());
}
} catch (Exception e) {
Log.e("adbKeyBoard", e.getMessage());
e.printStackTrace();
}
}

}

private void saveToFile(String filePath, String content) throws IOException {
File file = new File(filePath);
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close();
}

private List<ApplicationInfo> getAppInfos() {
PackageManager pm = getApplicationContext().getPackageManager();
List<ApplicationInfo> appList = pm
.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
return appList;
}
}
28 changes: 4 additions & 24 deletions keyboardservice/src/main/res/layout/keyboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,11 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Android从入门到放弃"
android:textSize="12sp"/>

<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Java从入门到放弃" />

<Button
android:id="@+id/button3"
android:orientation="vertical"
android:background="#808080">
<View
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="C#从入门到怀疑人生" />

<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="OC从入门到怀疑人生" />
android:layout_height="200dp"/>

<Button
android:id="@+id/button5"
Expand Down