├── settings.gradle
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── ic_launcher-web.png
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── unknow.png
│ │ │ │ ├── ic_baseline_hourglass_top_24.xml
│ │ │ │ ├── ic_info_black_24dp.xml
│ │ │ │ ├── ic_apps_black_24dp.xml
│ │ │ │ ├── ic_search_24dp.xml
│ │ │ │ ├── ic_search_black_24dp.xml
│ │ │ │ ├── ic_rounded_corner_black_24dp.xml
│ │ │ │ ├── bg_buttom_border_only.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── values
│ │ │ │ ├── ic_launcher_background.xml
│ │ │ │ ├── styles.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── strings.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ ├── splash_activity.xml
│ │ │ │ ├── applist_item.xml
│ │ │ │ ├── applist_activity.xml
│ │ │ │ ├── appbeta_activity.xml
│ │ │ │ └── activity_setting.xml
│ │ │ └── values-zh
│ │ │ │ └── strings.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── tumuyan
│ │ │ │ └── fixedplay
│ │ │ │ ├── App
│ │ │ │ ├── Item.java
│ │ │ │ ├── ItemAdapter.java
│ │ │ │ └── SelectOne.java
│ │ │ │ ├── Beta
│ │ │ │ ├── IntentFilter.java
│ │ │ │ ├── mixAdapter.java
│ │ │ │ ├── readFile.java
│ │ │ │ └── SelectApp.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── SettingActivity.java
│ │ └── AndroidManifest.xml
│ └── test
│ │ └── java
│ │ └── com
│ │ └── tumuyan
│ │ └── fixedplay
│ │ └── ExampleUnitTest.java
├── proguard-rules.pro
└── build.gradle
├── demo.jpg
├── screen_chs.jpg
├── screen_eng.jpg
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | /release/
3 |
--------------------------------------------------------------------------------
/demo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/demo.jpg
--------------------------------------------------------------------------------
/screen_chs.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/screen_chs.jpg
--------------------------------------------------------------------------------
/screen_eng.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/screen_eng.jpg
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/unknow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/app/src/main/res/drawable/unknow.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | /.gradle
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumuyan/AnyLauncher/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008375
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_baseline_hourglass_top_24.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_info_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/tumuyan/fixedplay/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.tumuyan.fixedplay;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_apps_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/splash_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_search_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_search_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_rounded_corner_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AnyLauncher
2 | You can choose any Android application and set it as a Launcher.
3 |
4 | ## Download | 下载
5 | [Github Release](https://github.com/tumuyan/AnyLauncher/releases)
6 |
7 | ## About | 关于
8 | 
9 | 
10 | 
11 | 可以选择任意一个应用把他设置为Launcher.
12 | 似乎并没有什么卵用?
13 | 如果你把一台安卓设备当成专用机(电子相册、电子菜单、手持终端),使用AnyLauncher就可以一定程度屏蔽home键,让用户哪怕误操作跳到其他应用中后,一按home又回来了。
14 | 当然如果你花钱订制了专用机的软硬件,这样的功能应该有了吧 吧 吧 吧 吧。
15 |
16 | 有两个工作模式:
17 | 1. 按下Home键,启动指定应用
18 | 2. 连续快速按下三次Home键,启动备用启动器
19 |
20 | 工作模式1又有多种设置模式:
21 | 1. 每次按下home键,都重新打开选中的应用的默认Activity;
22 | 2. 每次按下home键,把选中的应用切换到前台
23 | 3. 打开指定网页、地图、电话拨号、应用的具体Activity、快捷方式等
24 |
25 | 目前无法保证能跳转到系统默认Launcher选择器的界面,百度到的方法似乎都不怎么好用。如果有简单的demo请联系我
26 |
27 |
28 | ## Build Environment
29 | * Android Gradle Plugin 3.2.1
30 | * Gradle 4.6
31 | * Oracle OpenJDK 1.8
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_buttom_border_only.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
9 |
10 | -
11 |
12 |
13 |
14 |
15 |
16 | -
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 34
5 | buildToolsVersion '29.0.2'
6 | defaultConfig {
7 | applicationId "com.tumuyan.fixedplay"
8 | minSdkVersion 9
9 | targetSdkVersion 29
10 | versionCode 14
11 | versionName "1.13"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | vectorDrawables.useSupportLibrary = true
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | android.applicationVariants.all {
22 | variant ->
23 | variant.outputs.all {
24 | outputFileName = "Anylauncher-${variant.versionName}.apk"
25 | }
26 | }
27 | compileOptions {
28 | sourceCompatibility JavaVersion.VERSION_1_8
29 | targetCompatibility JavaVersion.VERSION_1_8
30 | }
31 | }
32 |
33 | dependencies {
34 | implementation fileTree(include: ['*.jar'], dir: 'libs')
35 | // implementation 'com.android.support.constraint:constraint-layout:1.1.3'
36 | implementation 'com.android.support:support-v4:25.4.0' // support-v4:26 need minSdkVersion 14
37 | // implementation 'com.android.support:appcompat-v7:25.0.0'
38 | // implementation 'com.android.support:support-v4:28.0.0'
39 | // implementation 'com.android.support:support-vector-drawable:28.0.0'
40 | testImplementation 'junit:junit:4.13.2'
41 | // androidTestImplementation 'com.android.support.test:runner:1.0.2'
42 | // androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
43 | implementation 'net.dongliu:apk-parser:2.6.4'
44 |
45 | implementation 'com.github.bumptech.glide:glide:3.8.0'
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/res/values-zh/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | AnyLauncher
4 | 设置任意应用为启动器
5 | 选择启动模式
6 | 当前选中应用
7 | 切换后台应用
8 | 打开应用主界面
9 | 设置桌面
10 | 选择应用
11 | 此应用可能无法设置为Launcher
12 | 这个功能看可能并没什么卵用,\n还是手动在系统里设置吧\n有解决问题的demo请联系我
13 | 搜索
14 |
15 | 模式%1$s启动应用时发生了错误"
16 |
17 |
18 | - 优先从后台切换到前台
19 | - 重新打开应用Activity
20 | - 浏览网页
21 | - 打开地图
22 | - 拨打电话
23 | - 打开文件
24 | - 特定Activity
25 | - 快捷方式
26 | - 备用启动器
27 |
28 |
29 |
30 | - 延迟时间(毫秒)
31 | - 图片的文件路径或网址
32 |
33 |
34 | 网址链接
35 | 地图坐标
36 | 电话号码
37 | 文件路径
38 |
39 | 确定
40 | 取消
41 |
42 | 备用启动器
43 | 延迟启动
44 | 延迟(开机后第一次用Anylauncher启动应用时,做延时处理)
45 | 三击Home生效
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/applist_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
17 |
18 |
25 |
26 |
34 |
35 |
42 |
43 |
44 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tumuyan/fixedplay/App/Item.java:
--------------------------------------------------------------------------------
1 | package com.tumuyan.fixedplay.App;
2 |
3 | import android.graphics.drawable.Drawable;
4 |
5 | public class Item {
6 | private String name;
7 | private String packageName;
8 | private String className="";
9 | private Drawable appIcon;
10 | private String ext="";
11 |
12 | /*
13 | private int position=0;
14 |
15 | public void setPosition(int position) {
16 | this.position = position;
17 | }
18 |
19 | public int getPosition() {
20 | return position;
21 | }*/
22 | public Item(){
23 |
24 | }
25 | public Item(String name, String packageName){
26 | this.name=name;
27 | this.packageName=packageName;
28 |
29 | }
30 | public Item(String name, String packageName, Drawable appIcon){
31 | this.name=name;
32 | this.packageName=packageName;
33 | this.appIcon=appIcon;
34 | }
35 |
36 | public Item(String name,String packageName, String className,Drawable appIcon){
37 | this.name=name;
38 | this.packageName=packageName;
39 | this.className=className;
40 | this.appIcon=appIcon;
41 | }
42 |
43 | public Item(String name,String packageName, String className,Drawable appIcon,Object ext){
44 | this.name=name;
45 | this.packageName=packageName;
46 | this.className=className;
47 | this.appIcon=appIcon;
48 | this.ext=""+ext;
49 | }
50 |
51 | public void setClassName(String className) {
52 | this.className = className;
53 | }
54 |
55 | public String getClassName() {
56 | return className;
57 | }
58 |
59 | public Drawable getAppIcon() {
60 | return appIcon;
61 | }
62 |
63 | public String getPackageName() {
64 | return packageName;
65 | }
66 |
67 | public String getName() {
68 | return name;
69 | }
70 |
71 | public void setExt(Object ext) {
72 | this.ext = ""+ext;
73 | }
74 |
75 | public String getExt() {
76 | return ext;
77 | }
78 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/applist_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
15 |
25 |
26 |
36 |
37 |
38 |
46 |
47 |
48 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | AnyLauncher
4 | Choose any application as Launcher.
5 | By tumuyan,\n2018.11 to 2024.04
6 | Select Mode
7 | Selected App
8 | Switch application
9 | Open default Activity
10 | Launcher
11 | Select App
12 | Not supported application.
13 |
14 | This button may be not working.\nYou should manual find the Launcher Selecter from the System Setting
15 | Search
16 | mode %1$s: Error onStart()"
17 |
18 |
19 | - Callback from background
20 | - Restart Activity
21 | - Open Url
22 | - Open Map
23 | - Phone Call
24 | - Open File
25 | - Activity
26 | - Shortcut
27 | - 2nd Launcher
28 |
29 |
30 |
31 | - Delay time (ms)
32 | - Image url/path
33 |
34 |
35 | Http Url
36 | Longitude and latitude
37 | Telephone number
38 | File path
39 |
40 | OK
41 | Cancel
42 | 2nd Launcher
43 | Delay
44 | Delay when launching a app with Anylauncher for the first time after booting
45 | Click Home 3 times
46 |
48 |
49 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
27 |
28 |
29 |
30 |
31 |
32 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tumuyan/fixedplay/Beta/IntentFilter.java:
--------------------------------------------------------------------------------
1 | package com.tumuyan.fixedplay.Beta;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class IntentFilter {
6 |
7 | public class StringPair{
8 | String name,value;
9 |
10 | StringPair(String name,String value){
11 | this.name=name;
12 | this.value=value;
13 | }
14 |
15 | public void setValue(String value) {
16 | this.value = value;
17 | }
18 |
19 | public void setName(String name) {
20 | this.name = name;
21 | }
22 |
23 | public String getName() {
24 | return name;
25 | }
26 |
27 | public String getValue() {
28 | return value;
29 | }
30 | }
31 |
32 | private ArrayList action=new ArrayList<>();
33 | private ArrayList category=new ArrayList<>();
34 | private ArrayList data=new ArrayList<>();
35 | //未完成
36 |
37 | IntentFilter(){
38 |
39 | }
40 |
41 | public void clear(){
42 | action.clear();
43 | category.clear();
44 | data.clear();
45 | }
46 |
47 | public void addAction(String Action){
48 | // action.remove(Action);
49 | action.add(Action);
50 | }
51 | public void addCategory(String Category){
52 | // category.remove(Category);
53 | category.add(Category);
54 | }
55 |
56 | public ArrayList getAction() {
57 | return action;
58 | }
59 |
60 | public ArrayList getCategory() {
61 | return category;
62 | }
63 |
64 | public ArrayList getData() {
65 | return data;
66 | }
67 |
68 | public ArrayList getData(String name) {
69 |
70 | return data;
71 | }
72 |
73 | public int getActionSize(){
74 | return action.size();
75 | }
76 |
77 | public int getCategorySize(){
78 | return category.size();
79 | }
80 |
81 | public boolean hasContent(){
82 | if(action.size()+category.size()>0){
83 | return true;
84 | }
85 | return false;
86 | }
87 |
88 | public String getString(){
89 | String result="";
90 | for(String s:action){
91 | result=result+"action:"+s+"\n";
92 | }
93 | for(String s:category){
94 | result=result+"category:"+s+"\n";
95 | }
96 | return result;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/appbeta_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
25 |
26 |
35 |
36 |
44 |
45 |
46 |
51 |
52 |
53 |
59 |
60 |
61 |
62 |
63 |
68 |
69 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tumuyan/fixedplay/Beta/mixAdapter.java:
--------------------------------------------------------------------------------
1 |
2 | package com.tumuyan.fixedplay.Beta;
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.content.SharedPreferences;
6 | import android.content.pm.PackageManager;
7 | import android.util.Log;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.ArrayAdapter;
12 | import android.widget.ImageView;
13 | import android.widget.TextView;
14 | import android.widget.Toast;
15 |
16 | import com.tumuyan.fixedplay.App.Item;
17 | import com.tumuyan.fixedplay.R;
18 | import com.tumuyan.fixedplay.SettingActivity;
19 |
20 | import java.util.List;
21 |
22 | import static android.content.Context.MODE_MULTI_PROCESS;
23 |
24 |
25 | /**
26 | * Created by baniel on 1/19/17.
27 | */
28 | public class mixAdapter extends ArrayAdapter- {
29 | private int layoutId;
30 | private String mode="r2";
31 | private String uri="";
32 |
33 | public mixAdapter(Context context, int layoutId, List
- list) {
34 | super(context, layoutId, list);
35 | this.layoutId = layoutId;
36 | }
37 | public void setMode(String mode) {
38 | this.mode = mode;
39 | }
40 |
41 | public void setUri(String uri) {
42 | this.uri = uri;
43 | }
44 |
45 | // @NonNull
46 | @Override
47 | public View getView(final int position, View convertView, final ViewGroup parent) {
48 |
49 | final Item item = getItem(position);
50 | View view = LayoutInflater.from(getContext()).inflate(layoutId, parent, false);
51 | final String packageName=item.getPackageName();
52 | final String className=item.getClassName();
53 | final String Name=item.getName();
54 |
55 | String _class, _package, _name;
56 | if(className.length()<1) {
57 | _name=Name;
58 | _package=packageName;
59 | }else if(className.contains(packageName)){
60 | _class=className.replace(packageName,"");
61 | _package=packageName;
62 | _name=Name+"("+_class+")";
63 | }else {
64 | _name=Name;
65 | _package=packageName+"\n"+className;
66 | }
67 |
68 | ((ImageView) view.findViewById(R.id.item_img)).setImageDrawable(item.getAppIcon());
69 | ((TextView) view.findViewById(R.id.item_text)).setText(_name);
70 | ((TextView)view.findViewById(R.id.item_packageName)).setText(_package);
71 | view.setOnClickListener(new View.OnClickListener() {
72 | @Override
73 | public void onClick(View v) {
74 | mOnItemDeleteListener.onDeleteClick(position);
75 | }
76 | });
77 |
78 |
79 |
80 | return view;
81 | }
82 | /**
83 | * 删除按钮的监听接口
84 | */
85 | public interface onItemDeleteListener {
86 | void onDeleteClick(int i);
87 | }
88 |
89 | private onItemDeleteListener mOnItemDeleteListener;
90 |
91 | public void setOnItemDeleteClickListener(onItemDeleteListener mOnItemDeleteListener) {
92 | this.mOnItemDeleteListener = mOnItemDeleteListener;
93 | }
94 | }
95 |
96 |
97 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tumuyan/fixedplay/App/ItemAdapter.java:
--------------------------------------------------------------------------------
1 |
2 | package com.tumuyan.fixedplay.App;
3 |
4 | import static android.content.Context.MODE_MULTI_PROCESS;
5 |
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.content.SharedPreferences;
9 | import android.content.pm.PackageManager;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.ArrayAdapter;
14 | import android.widget.ImageView;
15 | import android.widget.TextView;
16 | import android.widget.Toast;
17 |
18 | import com.tumuyan.fixedplay.R;
19 | import com.tumuyan.fixedplay.SettingActivity;
20 |
21 | import java.util.List;
22 |
23 |
24 | /**
25 | * Created by baniel on 1/19/17.
26 | */
27 |
28 | public class ItemAdapter extends ArrayAdapter
- {
29 | private int layoutId;
30 | private String mode="r2";
31 | private String uri="";
32 | // SQLiteDatabase db=SQLiteDatabase.openOrCreateDatabase(getContext().getDatabasePath("app"),null);
33 |
34 | public ItemAdapter(Context context, int layoutId, List
- list) {
35 | super(context, layoutId, list);
36 | this.layoutId = layoutId;
37 | }
38 |
39 |
40 | public void setMode(String mode) {
41 | this.mode = mode;
42 | }
43 |
44 | public void setUri(String uri) {
45 | this.uri = uri;
46 | }
47 |
48 | private static class ViewHolder {
49 | public ViewHolder(View viewRoot) {
50 | item_img = (ImageView) viewRoot.findViewById(R.id.item_img);
51 | item_text = (TextView) viewRoot.findViewById(R.id.item_text);
52 | item_packageName = (TextView) viewRoot.findViewById(R.id.item_packageName);
53 | }
54 |
55 | ImageView item_img;
56 | TextView item_text;
57 | TextView item_packageName;
58 | }
59 |
60 | // @NonNull
61 | @Override
62 | public View getView(final int position, View convertView, final ViewGroup parent) {
63 | final Item item = getItem(position);
64 | if (convertView == null) {
65 | convertView = LayoutInflater.from(getContext()).inflate(layoutId, parent, false);
66 | ViewHolder holder = new ViewHolder(convertView);
67 | convertView.setTag(holder);
68 | }
69 | final String packageName = item.getPackageName();
70 | final String className = item.getClassName();
71 | final String Name = item.getName();
72 |
73 | String _class, _package, _name;
74 | if (className.length() < 1) {
75 | _name = Name;
76 | _package = packageName;
77 | } else if (className.contains(packageName)) {
78 | _class = className.replace(packageName, "");
79 | _package = packageName;
80 | _name = Name + "(" + _class + ")";
81 | } else {
82 | _name = Name;
83 | _package = packageName + "\n" + className;
84 | }
85 |
86 | ViewHolder holder = (ViewHolder) convertView.getTag();
87 | holder.item_img.setImageDrawable(null);
88 | holder.item_img.setImageDrawable(item.getAppIcon());
89 | holder.item_text.setText(_name);
90 | holder.item_packageName.setText(_package);
91 | convertView.setOnClickListener(new View.OnClickListener() {
92 | @Override
93 | public void onClick(View v) {
94 | select(Name,packageName,className);
95 | }
96 | });
97 | return convertView;
98 | }
99 |
100 |
101 |
102 | public void select(String Name, String packageName, String className){
103 |
104 | if(mode.equals("2nd")){
105 | SharedPreferences.Editor editor = getContext(). getSharedPreferences("setting",MODE_MULTI_PROCESS).edit();
106 | editor.putString("app_2nd", packageName);
107 | editor.putString("label_2nd", Name);
108 | editor.putString("class_2nd",className);
109 | editor.commit();
110 | Intent intent=new Intent(getContext() ,SettingActivity.class);
111 | getContext().startActivity(intent);
112 | }else{
113 | PackageManager pm =getContext(). getPackageManager();
114 | Intent intent = pm.getLaunchIntentForPackage(packageName);
115 |
116 | if (intent != null) {
117 |
118 | {
119 | SharedPreferences.Editor editor = getContext(). getSharedPreferences("setting",MODE_MULTI_PROCESS).edit();
120 | editor.putString("app", packageName);
121 | editor.putString("label", Name);
122 | editor.putString("class",className);
123 | editor.putString("uri",uri);
124 | editor.putString("mode",mode);
125 | editor.commit();
126 | }
127 |
128 | // getContext().startActivity(intent);
129 | intent=new Intent(getContext() ,SettingActivity.class);
130 | getContext().startActivity(intent);
131 |
132 | }else{
133 | Toast.makeText(getContext(),R.string.error_could_not_start,Toast.LENGTH_SHORT).show();
134 | }
135 |
136 | }
137 |
138 |
139 | }
140 |
141 |
142 | /**
143 | * @param
144 | * @描述 通过包名启动其他应用,假如应用已经启动了在后台运行,则会将应用切到前台
145 | * @作者 tll
146 | * @时间 2017/2/7 17:40
147 | */
148 | public static void startActivityForPackage(Context context, String packName) {
149 | Intent intent = context.getPackageManager().getLaunchIntentForPackage(packName);
150 | context.startActivity(intent);
151 | }
152 |
153 |
154 | }
155 |
156 |
157 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_setting.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
13 |
16 |
17 |
21 |
22 |
28 |
29 |
37 |
38 |
51 |
52 |
53 |
61 |
62 |
67 |
68 |
74 |
75 |
82 |
83 |
94 |
95 |
103 |
104 |
105 |
106 |
114 |
115 |
123 |
124 |
125 |
126 |
131 |
132 |
139 |
140 |
155 |
156 |
171 |
172 |
173 |
188 |
189 |
190 |
191 |
192 |
198 |
199 |
208 |
209 |
220 |
221 |
231 |
232 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tumuyan/fixedplay/App/SelectOne.java:
--------------------------------------------------------------------------------
1 | package com.tumuyan.fixedplay.App;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.content.pm.PackageInfo;
6 | import android.content.pm.PackageManager;
7 | import android.content.pm.ResolveInfo;
8 | import android.graphics.drawable.Drawable;
9 | import android.net.Uri;
10 | import android.os.Bundle;
11 | import android.util.Log;
12 | import android.view.KeyEvent;
13 | import android.view.View;
14 | import android.widget.Button;
15 | import android.widget.EditText;
16 | import android.widget.ListView;
17 | import android.widget.ProgressBar;
18 |
19 | import com.tumuyan.fixedplay.R;
20 |
21 | import java.io.File;
22 | import java.util.ArrayList;
23 | import java.util.List;
24 |
25 |
26 | public class SelectOne extends Activity {
27 | // Adapter显示项目(筛选后
28 | private List
- list = new ArrayList<>();
29 | // 原始搜索结果
30 | private List
- listOrgin = new ArrayList<>();
31 |
32 | private ListView listView;
33 | private ProgressBar progressBar;
34 | private String _mode, _action, _uri;
35 |
36 | private View SearchBox;
37 | private EditText SearchText;
38 | private Button SearchButton;
39 | ItemAdapter itemAdapter;
40 | private Drawable defaultIcon;
41 |
42 | @Override
43 | protected void onCreate(Bundle savedInstanceState) {
44 | super.onCreate(savedInstanceState);
45 | setContentView(R.layout.applist_activity);
46 | progressBar = (ProgressBar) findViewById(R.id.progressBar);
47 | SearchBox = (View) findViewById(R.id.searchBox);
48 | SearchButton = (Button) findViewById(R.id.button_filter);
49 | SearchText = (EditText) findViewById(R.id.editText_filter);
50 | SearchBox.setVisibility(View.GONE);
51 | Intent intent = getIntent();
52 | _mode = intent.getStringExtra("_mode");
53 | _action = intent.getStringExtra("_action");
54 | _uri = intent.getStringExtra("_uri");
55 | defaultIcon = getResources().getDrawable(R.drawable.unknow);
56 |
57 | new Thread(new Runnable() {
58 | @Override
59 | public void run() {
60 | // getAppList();
61 | loadAllApps(makeIntent());
62 | list.addAll(listOrgin);
63 |
64 | itemAdapter = new ItemAdapter(SelectOne.this, R.layout.applist_item, list);
65 | itemAdapter.setMode(_mode);
66 | itemAdapter.setUri(_uri);
67 | runOnUiThread(new Runnable() {
68 | @Override
69 | public void run() {
70 | //耗时操作,需要在子线程中完成操作后通知主线程实现UI更新
71 | listView = (ListView) findViewById(R.id.listview);
72 | if (listView == null) Log.e("listitem", "null");
73 | listView.setAdapter(itemAdapter);
74 | progressBar.setVisibility(View.GONE);
75 | SearchBox.setVisibility(View.VISIBLE);
76 |
77 |
78 | listView.setOnKeyListener(new View.OnKeyListener() {
79 | @Override
80 | public boolean onKey(View v, int keyCode, KeyEvent event) {
81 | if (event.getAction() == KeyEvent.ACTION_UP)
82 | {
83 |
84 | if ( keyCode == KeyEvent.KEYCODE_SPACE || keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER || keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
85 |
86 | int selectedItemPosition = listView.getSelectedItemPosition();
87 | Log.i("App SelectorOne", "Keycode = " + keyCode + ", cursorPosition = " + selectedItemPosition);
88 | if (selectedItemPosition < 0) return false;
89 | Item item = list.get(selectedItemPosition);
90 | itemAdapter.select(item.getName(), item.getPackageName(), item.getClassName() );
91 | return true;
92 | }
93 | }
94 | return false;
95 | }
96 | });
97 |
98 | }
99 |
100 | });
101 |
102 | }
103 |
104 | }).start();
105 |
106 | SearchButton.setOnClickListener(new View.OnClickListener() {
107 | @Override
108 | public void onClick(View view) {
109 | doSearch(SearchText.getText().toString());
110 | }
111 | });
112 |
113 | SearchText.setOnKeyListener(new View.OnKeyListener() {
114 | @Override
115 | public boolean onKey(View v, int keyCode, KeyEvent event) {
116 | if (event.getAction() == KeyEvent.ACTION_UP) {
117 | if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER || keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
118 | doSearch(SearchText.getText().toString());
119 | return true;
120 | }
121 | }
122 | return false;
123 | }
124 | });
125 | }
126 |
127 | //
128 | // class searchWatcher implements TextWatcher {
129 | // @Override
130 | // public void afterTextChanged(Editable s) {//表示最终内容 Log.d("afterTextChanged", s.toString());
131 | // }
132 | // // /** * * @param s * @param start 开始的位置 * @param count 被改变的旧内容数 * @param after 改变后的内容数量 */
133 | // @Override
134 | // public void beforeTextChanged (CharSequence s,int start, int count, int after)
135 | // { //这里的s表示改变之前的内容,通常start和count组合,可以在s中读取本次改变字段中被改变的内容。而after表示改变后新的内容的数量。
136 | // }
137 | // /** * * @param s * @param start 开始位置 * @param before 改变前的内容数量 * @param count 新增数 */
138 | // @Override
139 | // public void onTextChanged(CharSequence s, int start, int before, int count) {
140 | // //这里的s表示改变之后的内容,通常start和count组合,可以在s中读取本次改变字段中新的内容。而before表示被改变的内容的数量。
141 | // doSearch(s); }
142 | //
143 | // }
144 |
145 | private void doSearch(String str) {
146 | list.clear();
147 | for (int i = 0; i < listOrgin.size(); i++) {
148 | Item item = listOrgin.get(i);
149 | if (item.getClassName().contains(str) ||
150 | item.getPackageName().contains(str) ||
151 | item.getName().contains(str)) {
152 | list.add(item);
153 | }
154 | }
155 | Log.w("search", str + " get" + list.size());
156 | itemAdapter.notifyDataSetChanged();
157 | }
158 |
159 |
160 | @Override
161 | protected void onPause() {
162 | super.onPause();
163 | this.finish();
164 | }
165 | // 停用的旧方法
166 | private void getAppList() {
167 | PackageManager pm = getPackageManager();
168 | // Return a List of all packages that are installed on the device.
169 | List packages = pm.getInstalledPackages(0);
170 | for (PackageInfo packageInfo : packages) {
171 | // 判断系统/非系统应用
172 | /*
173 | if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) // 非系统应用
174 | {
175 | System.out.println("MainActivity.getAppList, packageInfo=" + packageInfo.packageName);
176 | } else {
177 | // 系统应用
178 | }
179 | */
180 |
181 | Item item = new Item(
182 | pm.getApplicationLabel(packageInfo.applicationInfo).toString(),
183 | packageInfo.applicationInfo.packageName,
184 | pm.getApplicationIcon(packageInfo.applicationInfo)
185 | );
186 |
187 | list.add(item);
188 |
189 | }
190 |
191 | }
192 |
193 |
194 | private void loadAllApps() {
195 | Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
196 | mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
197 |
198 | List mApps;
199 | mApps = new ArrayList<>();
200 | mApps.addAll(this.getPackageManager().queryIntentActivities(mainIntent, 0));
201 |
202 |
203 | /* 包名获取方法:resolve.activityInfo.packageName
204 | icon获取获取方法:resolve.loadIcon(packageManager)
205 | 应用名称获取方法:resolve.loadLabel(packageManager).toString()
206 | */
207 | PackageManager pm = getPackageManager();
208 |
209 |
210 | for (ResolveInfo r : mApps) {
211 | Drawable ic = r.loadIcon((pm));
212 | if (ic == null) ic = defaultIcon;
213 |
214 | Item item = new Item(
215 | r.loadLabel(pm).toString(),
216 | r.activityInfo.packageName,
217 | r.activityInfo.name,
218 | ic
219 | );
220 | list.add(item);
221 | }
222 |
223 | }
224 |
225 | // 唯一在用的新方法
226 | private void loadAllApps(Intent intent) {
227 | List mApps;
228 | mApps = new ArrayList<>();
229 | try {
230 | mApps.addAll(this.getPackageManager().queryIntentActivities(intent, 0));
231 |
232 | PackageManager pm = getPackageManager();
233 | for (ResolveInfo r : mApps) {
234 | Drawable ic = r.loadIcon((pm));
235 | if (ic == null) ic = defaultIcon;
236 |
237 | Item item = new Item(
238 | r.loadLabel(pm).toString(),
239 | r.activityInfo.packageName,
240 | r.activityInfo.name,
241 | ic
242 | );
243 | listOrgin.add(item);
244 | }
245 | Log.w("load", "" + listOrgin.size());
246 | } catch (Exception e) {
247 | e.printStackTrace();
248 | }
249 |
250 | }
251 |
252 | private Intent makeIntent() {
253 |
254 | switch (_mode) {
255 | case "r2":
256 | case "r1":
257 | Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
258 | mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
259 | return mainIntent;
260 | case "uri": {
261 | Uri uri = Uri.parse(_uri);
262 | Intent it = new Intent(Intent.ACTION_VIEW, uri);
263 | return it;
264 | }
265 |
266 | case "uri_dail": {
267 | Uri uri = Uri.parse(_uri);
268 | Intent it = new Intent(Intent.ACTION_DIAL, uri);
269 | return it;
270 | }
271 |
272 | case "uri_file": {
273 | File f = (new File(_uri));
274 | Intent intent = new Intent();
275 | intent.setAction(Intent.ACTION_VIEW);
276 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
277 | intent.setDataAndType(Uri.fromFile(f), "*/*");
278 | return intent;
279 | }
280 |
281 | case "2nd": {
282 | Intent intent = new Intent();
283 | intent.setAction(Intent.ACTION_MAIN);
284 | // intent.setAction(Intent.ACTION_VIEW);
285 | intent.addCategory("android.intent.category.HOME");
286 | return intent;
287 |
288 | }
289 | case "short_cut": {
290 | Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
291 |
292 | return shortcutsIntent;
293 | }
294 |
295 | }
296 | return null;
297 |
298 | }
299 |
300 |
301 |
302 | }
303 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tumuyan/fixedplay/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.tumuyan.fixedplay;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.content.SharedPreferences;
6 | import android.content.pm.PackageManager;
7 | import android.net.Uri;
8 | import android.os.Bundle;
9 | import android.os.Handler;
10 | import android.os.Message;
11 | import android.os.SystemClock;
12 | import android.util.Log;
13 | import android.view.KeyEvent;
14 | import android.view.View;
15 | import android.widget.ImageView;
16 | import android.widget.Toast;
17 |
18 |
19 | import com.bumptech.glide.Glide;
20 |
21 | import java.io.File;
22 |
23 | public class MainActivity extends Activity {
24 |
25 | PackageManager packageManager;
26 | final String THIS_PACKAGE = "com.tumuyan.fixedplay";
27 | long splash_time = 0;
28 | String mode = "r2", action = "";
29 | ImageView imgview = null;
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | packageManager = getPackageManager();
34 | Log.w("MainActivity", "Create");
35 |
36 | SharedPreferences read = getSharedPreferences("setting", MODE_MULTI_PROCESS);
37 | final String splash_img = read.getString("splash_img", "");
38 |
39 | splash_time = read.getInt("splash_time", 0);
40 |
41 | Log.w("MainActivity", "Create, splash_time = " + splash_time);
42 | // if (System.currentTimeMillis() - SystemClock.elapsedRealtime() >60000 ){
43 | // splash_time =0;
44 | // }
45 | if (splash_time > 0) {
46 | handler.sendEmptyMessageDelayed(GO, splash_time);
47 | setContentView(R.layout.splash_activity);
48 | imgview = findViewById(R.id.splash_img);
49 | imgview.setOnClickListener(new View.OnClickListener() {
50 | @Override
51 | public void onClick(View v) {
52 | skip_splash();
53 | }
54 | });
55 | Glide.with(this)
56 | .load(splash_img)
57 | .placeholder(R.drawable.ic_baseline_hourglass_top_24)
58 | // .asGif()
59 | .into(imgview);
60 | }
61 |
62 | super.onCreate(savedInstanceState);
63 | }
64 |
65 | private void skip_splash() {
66 | if (imgview != null) {
67 | handler.removeMessages(GO);
68 | splash_time = 0;
69 | imgview.setImageDrawable(null);
70 | go();
71 | }
72 | }
73 |
74 | @Override
75 | public void onStart() {
76 | Log.w("MainActivity", "Start");
77 | super.onStart();
78 | }
79 |
80 | @Override
81 | public void onResume() {
82 | Log.w("MainActivity", String.format("Resume, splash %d", splash_time));
83 | if (splash_time <= 0)
84 | go();
85 | super.onResume();
86 | }
87 |
88 |
89 | public void go() {
90 | SharedPreferences read = getSharedPreferences("setting", MODE_MULTI_PROCESS);
91 | String app = read.getString("app", "");
92 | String claseName = read.getString("class", "");
93 | String uri = read.getString("uri", "");
94 | mode = read.getString("mode", "r2");
95 | action = read.getString("action", "");
96 | Log.i("MainActivity.go()", "mode=" + mode + ", packagename=" + app);
97 |
98 | boolean apply2nd = read.getBoolean("apply2nd", false);
99 | long lastTime = read.getLong("lastTime", 0);
100 | int combo = read.getInt("combo", 0);
101 |
102 | final String app_2nd = read.getString("app_2nd", "");
103 | final String class_2nd = read.getString("class_2nd", "");
104 | Log.w("2nd", app_2nd + ", combo=" + combo);
105 |
106 | if (apply2nd) {
107 |
108 | long time = System.currentTimeMillis();
109 | if (combo > 3)
110 | combo = 0;
111 | else {
112 | if (time - lastTime < 500) {
113 | combo++;
114 | } else {
115 | combo = 0;
116 | }
117 | }
118 |
119 | Log.w("combo", "" + combo);
120 | {
121 | SharedPreferences.Editor editor = getSharedPreferences("setting", MODE_MULTI_PROCESS).edit();
122 | editor.putInt("combo", combo);
123 | editor.putLong("lastTime", time);
124 | editor.commit();
125 | }
126 | if (combo > 1) {
127 | if (app_2nd.length() > 0) {
128 | Intent intent = new Intent();
129 |
130 | intent = packageManager.getLaunchIntentForPackage(app_2nd);
131 | if (intent != null) {
132 | intent.addCategory(Intent.CATEGORY_HOME);
133 | Log.w("2nd2", "length>0 -> intent not null");
134 | startActivity(intent);
135 | } else {
136 | // Toast.makeText(SettingActivity.this,R.string.error_could_not_start,Toast.LENGTH_SHORT).show();
137 |
138 | intent = new Intent();
139 | intent.setAction(Intent.ACTION_MAIN);
140 | if (class_2nd.length() > 5) {
141 | intent.setClassName(app_2nd, class_2nd);
142 | }
143 | try {
144 | startActivity(intent);
145 | } catch (Exception e) {
146 | Log.e("startActivity", app_2nd + ", " + class_2nd);
147 | e.printStackTrace();
148 | Toast.makeText(MainActivity.this, R.string.error_could_not_start, Toast.LENGTH_SHORT).show();
149 | intent = new Intent(MainActivity.this, SettingActivity.class);
150 | startActivity(intent);
151 | }
152 | }
153 | } else {
154 | Intent intent = new Intent(MainActivity.this, SettingActivity.class);
155 | startActivity(intent);
156 | }
157 | return;
158 | }
159 | }
160 |
161 | if (app.length() > 0 && app != THIS_PACKAGE) {
162 | switch (mode) {
163 | case "r2": {
164 | Log.w("MainActivity mode2", mode);
165 | Intent intent = packageManager.getLaunchIntentForPackage(app);
166 | if (intent != null) startActivity(intent);
167 | break;
168 | }
169 |
170 | case "r1":
171 | /* */
172 | if (claseName.length() > 5) {
173 | Intent intent = new Intent();
174 | intent.setClassName(app, claseName);
175 | startActivity(intent);
176 | } else {
177 | // Log.w("MainActivity mode1" ,mode);
178 | Intent intent = new Intent();
179 | intent = packageManager.getLaunchIntentForPackage(app);
180 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP);
181 | this.startActivity(intent);
182 | }
183 | break;
184 | case "beta":
185 | /* */
186 | {
187 |
188 |
189 | Intent intent = new Intent();
190 |
191 | if (action.length() > 0 && !"none".equals(action)) {
192 | intent.setAction(action);
193 | }
194 |
195 | if (claseName.length() > 5) {
196 | intent.setClassName(app, claseName);
197 |
198 | } else {
199 | intent = packageManager.getLaunchIntentForPackage(app);
200 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP);
201 |
202 | }
203 | try {
204 | startActivity(intent);
205 | } catch (Exception e) {
206 | e.printStackTrace();
207 | // Toast.makeText(this,getString(R.string.toast_main_start_error,mode)"模式"+mode + "启动应用时发生了错误",Toast.LENGTH_SHORT).show();
208 | Toast.makeText(this, getString(R.string.toast_main_start_error, mode), Toast.LENGTH_SHORT).show();
209 | intent = new Intent(MainActivity.this, SettingActivity.class);
210 | startActivity(intent);
211 |
212 | }
213 |
214 |
215 | }
216 |
217 |
218 | break;
219 |
220 | case "uri": {
221 | Uri u = Uri.parse(uri);
222 | Intent intent = new Intent(Intent.ACTION_VIEW, u);
223 |
224 |
225 | if (claseName.length() > 0) {
226 | intent.setClassName(app, claseName);
227 | } else {
228 | intent.setPackage(app);
229 | }
230 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
231 |
232 | startActivity(intent);
233 | break;
234 | }
235 |
236 | /* 似乎没用*/
237 | case "uri_dail": {
238 | Uri u = Uri.parse(uri);
239 | Intent intent = new Intent(Intent.ACTION_DIAL, u);
240 | if (claseName.length() > 0) {
241 | intent.setClassName(app, claseName);
242 | } else {
243 | intent.setPackage(app);
244 | }
245 | startActivity(intent);
246 | break;
247 | }
248 |
249 | case "uri_file": {
250 | Intent intent = new Intent("android.intent.action.VIEW");
251 | intent.addCategory("android.intent.category.DEFAULT");
252 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
253 | if (claseName.length() > 0) {
254 | intent.setClassName(app, claseName);
255 | } else {
256 | intent.setPackage(app);
257 | }
258 | Uri u = Uri.fromFile(new File(uri));
259 | intent.setDataAndType(u, "*/*");
260 | startActivity(intent);
261 |
262 | break;
263 | }
264 |
265 |
266 | }
267 |
268 | } else {
269 | Intent intent = new Intent(MainActivity.this, SettingActivity.class);
270 | startActivity(intent);
271 | }
272 | }
273 |
274 |
275 | @Override
276 | public boolean onKeyDown(int keyCode, KeyEvent event) {
277 | if (keyCode == KeyEvent.KEYCODE_BACK) {
278 | //禁止使用返回键返回到上一页,但是可以直接退出程序
279 | return true;//不执行父类点击事件
280 | } else if (keyCode == KeyEvent.KEYCODE_ENTER) {
281 | // 跳过
282 | skip_splash();
283 | return true;
284 | }
285 | return super.onKeyDown(keyCode, event);//继续执行父类其他点击事件
286 | }
287 |
288 | private static final int GO = 1;
289 | Handler handler = new Handler() {
290 | @Override
291 | public void handleMessage(Message msg) {
292 | switch (msg.what) {
293 | case GO:
294 | go();
295 | splash_time = 0;
296 | break;
297 | }
298 | }
299 | };
300 | }
301 |
302 |
303 |
304 |
305 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tumuyan/fixedplay/Beta/readFile.java:
--------------------------------------------------------------------------------
1 | package com.tumuyan.fixedplay.Beta;
2 |
3 | import android.content.Context;
4 | import android.text.TextUtils;
5 | import android.util.Log;
6 | import android.util.Xml;
7 |
8 | import com.tumuyan.fixedplay.App.Item;
9 |
10 |
11 | import net.dongliu.apk.parser.ApkFile;
12 |
13 | import org.xmlpull.v1.XmlPullParser;
14 |
15 | import java.io.BufferedInputStream;
16 | import java.io.BufferedReader;
17 | import java.io.ByteArrayInputStream;
18 | import java.io.File;
19 | import java.io.FileInputStream;
20 | import java.io.FileOutputStream;
21 | import java.io.IOException;
22 | import java.io.InputStream;
23 | import java.io.InputStreamReader;
24 | import java.util.ArrayList;
25 | import java.util.zip.GZIPInputStream;
26 | import java.util.zip.ZipEntry;
27 | import java.util.zip.ZipFile;
28 | import java.util.zip.ZipInputStream;
29 |
30 | public class readFile {
31 |
32 | public static void parserAxml(String filePath){
33 | try {
34 | ApkFile apkFile = new ApkFile(new File(filePath));
35 | String manifestXml = apkFile.getManifestXml();
36 | String xml = apkFile.transBinaryXml("AndroidManifest.xml");
37 | // Log.w("get xml",xml);
38 | InputStream is = new ByteArrayInputStream(xml.getBytes());
39 |
40 | }catch (Exception e){
41 | e.printStackTrace();
42 | }
43 | }
44 |
45 | public static ArrayList pullXml (String path,String packageName,String activityName) throws Exception {
46 |
47 | // public ArrayList
- pull2xml(String packageName, Context context) throws Exception {
48 | // String path=context.getPackageManager().getApplicationInfo(packageName, 0).sourceDir;
49 | boolean findActivity=false;
50 | String result="";
51 | IntentFilter filter=new IntentFilter();
52 | ArrayList filters=new ArrayList<>();
53 |
54 | ApkFile apkFile = new ApkFile(new File(path));
55 | String manifestXml = apkFile.getManifestXml();
56 | String xml = apkFile.transBinaryXml("AndroidManifest.xml");
57 | // Log.w("get xml",xml);
58 | InputStream is = new ByteArrayInputStream(xml.getBytes());
59 | //创建xmlPull解析器
60 | XmlPullParser parser = Xml.newPullParser();
61 |
62 | ///初始化xmlPull解析器
63 | parser.setInput(is, "utf-8");
64 | //读取文件的类型
65 | int type = parser.getEventType();
66 | //无限判断文件类型进行读取
67 | while (type != XmlPullParser.END_DOCUMENT) {
68 | // Log.i("get ",parser.getAttributeCount());
69 | if(type==XmlPullParser.START_TAG && !findActivity){
70 |
71 | if (("activity".equals(parser.getName()))) {
72 | /* for(int i=parser.getAttributeCount()-1;i>-1;i--){
73 | Log.i("get activity att"+i,parser.getAttributeName(i)+"-"+parser.getAttributeValue(i));
74 | }*/
75 | String className = parser.getAttributeValue(null ,"name" );
76 | Log.i("get activity name",parser.getAttributeValue(null, "name")+"-aim:"+activityName);
77 | // Log.i("get activity a name",parser.getAttributeValue(null, "android:name")+"-aim:"+activityName);
78 | if (activityName.equals(className)) {
79 | findActivity = true;
80 | } else if (activityName.equals(packageName + className)) {
81 | findActivity = true;
82 | }else{
83 | Log.i("no mach","");
84 | }
85 | }
86 | }else if(type==XmlPullParser.START_TAG && findActivity){
87 |
88 | switch ((parser.getName())){
89 |
90 | case "intent-filter":
91 | filter.clear();
92 | break;
93 | case "action":
94 | filter.addAction(parser.getAttributeValue(null,"name"));
95 | break;
96 | case "category":
97 | filter.addCategory(parser.getAttributeValue(null,"name"));
98 | break;
99 |
100 | }
101 |
102 |
103 | }else if(type==XmlPullParser.END_TAG) {
104 |
105 | if("intent-filter".equals(parser.getName()) && filter.hasContent()){
106 | filters.add(filter);
107 | }
108 |
109 | else if ("activity".equals(parser.getName()) && findActivity) {
110 | break;
111 | }
112 |
113 | }
114 | //继续往下读取标签类型
115 | type = parser.next();
116 | }
117 |
118 | for(int i=0;i actions=new ArrayList<>();
123 | actions.add("none");
124 | actions.add("android.intent.action.MAIN");
125 | actions.add("android.intent.action.VIEW");
126 | for(IntentFilter intentFilter:filters){
127 | for(String action:intentFilter.getAction()){
128 | actions.remove(action);
129 | actions.add(action);
130 | }
131 | }
132 | /*
133 | String[] actionStr=new String[actions.size()];
134 | for(int i=0;i arrayList){
144 | String[] actionStr=new String[arrayList.size()];
145 | for(int i=0;i arrayList){
152 | String str="";
153 | for(String s:arrayList){
154 | str=str+"\n"+s;
155 | }
156 | return str;
157 | }
158 |
159 | public static String pull2xml(String path,String packageName,String activityName) throws Exception {
160 |
161 | // public ArrayList
- pull2xml(String packageName, Context context) throws Exception {
162 | // String path=context.getPackageManager().getApplicationInfo(packageName, 0).sourceDir;
163 | boolean findActivity=false;
164 | String result="";
165 | IntentFilter filter=new IntentFilter();
166 | ArrayList filters=new ArrayList<>();
167 |
168 | InputStream is=readAppFile(path);
169 | //创建xmlPull解析器
170 | XmlPullParser parser = Xml.newPullParser();
171 |
172 | ///初始化xmlPull解析器
173 | parser.setInput(is, "utf-8");
174 | //读取文件的类型
175 | int type = parser.getEventType();
176 | //无限判断文件类型进行读取
177 | while (type != XmlPullParser.END_DOCUMENT) {
178 | if(type==XmlPullParser.START_TAG && !findActivity){
179 |
180 | if ((parser.getName().equals("activity"))) {
181 | String className = parser.getAttributeValue("", "android:name");
182 | if (className.equals(activityName)) {
183 | findActivity = true;
184 | } else if (activityName.equals(packageName + className)) {
185 | findActivity = true;
186 | }
187 | }
188 | }else if(type==XmlPullParser.START_TAG && findActivity){
189 |
190 | switch ((parser.getName())){
191 |
192 | case "intent-filter":
193 | filter.clear();
194 | break;
195 | case "action":
196 | filter.addAction(parser.getAttributeValue("","android:name"));
197 | break;
198 | case "category":
199 | filter.addCategory(parser.getAttributeValue("","android:name"));
200 | break;
201 |
202 | }
203 |
204 |
205 | }else if(type==XmlPullParser.END_TAG) {
206 |
207 | if("intent-filter".equals(parser.getName()) && filter.hasContent()){
208 | filters.add(filter);
209 | }
210 |
211 | else if ("activity".equals(parser.getName()) && findActivity) {
212 | break;
213 | }
214 |
215 | }
216 | //继续往下读取标签类型
217 | type = parser.next();
218 | }
219 |
220 | for(int i=0;i list = new ArrayList<>();
39 | // 原始搜索结果
40 | private List
- listOrgin=new ArrayList<>();
41 |
42 |
43 | private ListView listView,listviewActivity;
44 | private ProgressBar progressBar;
45 | private String _mode,_action,_uri;
46 |
47 | private View SearchBox;
48 | private EditText SearchText;
49 | private Button SearchButton;
50 | private mixAdapter itemAdapter;
51 | private Drawable defaultIcon;
52 | private Boolean showActivity=false;
53 | private PackageManager pm;
54 | private String packageName="", label="",action,className;
55 | private TextView TextBottom ;
56 |
57 |
58 | @Override
59 | protected void onCreate(Bundle savedInstanceState) {
60 | super.onCreate(savedInstanceState);
61 | setContentView(R.layout.appbeta_activity);
62 | TextBottom=(TextView)findViewById(R.id.textBottom);
63 | progressBar=(ProgressBar)findViewById(R.id.progressBar);
64 | SearchBox=(View)findViewById(R.id.searchBox);
65 | SearchButton=(Button)findViewById(R.id.button_filter);
66 | SearchText=(EditText) findViewById(R.id.editText_filter);
67 | SearchBox.setVisibility(View.GONE);
68 | listView = (ListView) findViewById(R.id.listview);
69 | listviewActivity=(ListView)findViewById(R.id.listview_acitivity);
70 | listviewActivity.setVisibility(View.GONE);
71 |
72 | defaultIcon=getResources().getDrawable(R.drawable.unknow);
73 |
74 | itemAdapter = new mixAdapter(SelectApp.this, R.layout.applist_item, list);
75 | itemAdapter.setMode(_mode);
76 | itemAdapter.setUri(_uri);
77 | /* listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
78 | @Override
79 | public void onItemClick(AdapterView> adapterView, View view, int i, long l) {
80 | Log.w("selectapp","1"+",i"+i+",L"+l);
81 | // Toast.makeText(SelectApp.this, "Click item" + i, Toast.LENGTH_SHORT).show();
82 | }
83 | });*/
84 | //ListView item 中的删除按钮的点击事件
85 | itemAdapter.setOnItemDeleteClickListener(new mixAdapter.onItemDeleteListener() {
86 | @Override
87 | public void onDeleteClick(int i) {
88 |
89 |
90 | if(showActivity){
91 | // TextBottom.setText(list.get(i).getExt());
92 | try{
93 | String path=getPackageManager().getApplicationInfo(packageName, 0).sourceDir;
94 | className=list.get(i).getClassName();
95 | if(className.matches("^\\..*")){
96 | className=packageName+className;
97 | }
98 | label=list.get(i).getName();
99 | ArrayList actions= readFile.pullXml(path,packageName,className);
100 | if(actions.size()>0){
101 | final String[] actionStr=new String[actions.size()];
102 | for(int j=0;j scoredA=new ArrayList<>();
273 | ArrayList
- scoredB=new ArrayList<>();
274 | for(int i=0;i packages = pm.getInstalledPackages(0);
315 | for (PackageInfo packageInfo : packages) {
316 | // 判断系统/非系统应用
317 | /*
318 | if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) // 非系统应用
319 | {
320 | System.out.println("MainActivity.getAppList, packageInfo=" + packageInfo.packageName);
321 | } else {
322 | // 系统应用
323 | }
324 | */ Drawable ic= pm.getApplicationIcon(packageInfo.applicationInfo);
325 | if(null==ic) ic=defaultIcon;
326 |
327 | Item item = new Item(
328 | pm.getApplicationLabel(packageInfo.applicationInfo).toString(),
329 | packageInfo.applicationInfo.packageName,
330 | ic
331 | );
332 |
333 | listOrgin.add(item);
334 |
335 | }
336 |
337 | }
338 |
339 |
340 | private void loadAllApps() {
341 | Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
342 | mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
343 |
344 | List mApps;
345 | mApps = new ArrayList<>();
346 | mApps.addAll(this.getPackageManager().queryIntentActivities(mainIntent, 0));
347 |
348 |
349 | /* 包名获取方法:resolve.activityInfo.packageName
350 | icon获取获取方法:resolve.loadIcon(packageManager)
351 | 应用名称获取方法:resolve.loadLabel(packageManager).toString()
352 | */
353 | PackageManager pm = getPackageManager();
354 |
355 |
356 |
357 | for(ResolveInfo r:mApps){
358 | Drawable ic=r.loadIcon((pm));
359 | if(ic==null) ic=defaultIcon;
360 |
361 | Item item = new Item(
362 | r.loadLabel(pm).toString(),
363 | r.activityInfo.packageName,
364 | r.activityInfo.name,
365 | ic
366 | );
367 | list.add(item);
368 | }
369 |
370 | }
371 |
372 | // 唯一在用的新方法
373 | private void loadAllApps(Intent intent) {
374 | List mApps;
375 | mApps = new ArrayList<>();
376 | try {
377 | mApps.addAll(this.getPackageManager().queryIntentActivities(intent, 0));
378 |
379 | PackageManager pm = getPackageManager();
380 | for (ResolveInfo r : mApps) {
381 | Drawable ic=r.loadIcon((pm));
382 | if(ic==null) ic=defaultIcon;
383 |
384 | Item item = new Item(
385 | r.loadLabel(pm).toString(),
386 | r.activityInfo.packageName,
387 | r.activityInfo.name,
388 | ic
389 | );
390 | listOrgin.add(item);
391 | }
392 | Log.w("load",""+listOrgin.size());
393 | }catch (Exception e){
394 | e.printStackTrace();
395 | }
396 |
397 | }
398 |
399 | private Intent makeIntent(){
400 |
401 | switch (_mode){
402 | case "r2":
403 | case "r1":
404 | Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
405 | mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
406 | return mainIntent;
407 | case "uri":
408 | {
409 | Uri uri = Uri.parse(_uri);
410 | Intent it = new Intent(Intent.ACTION_VIEW,uri);
411 | return it;
412 | }
413 |
414 | case "uri_dail":
415 | {
416 | Uri uri = Uri.parse(_uri);
417 | Intent it = new Intent(Intent.ACTION_DIAL, uri);
418 | return it;
419 | }
420 |
421 | case "uri_file":
422 | { File f=(new File(_uri));
423 | Intent intent = new Intent();
424 | intent.setAction(Intent.ACTION_VIEW);
425 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
426 | intent.setDataAndType(Uri.fromFile(f), "*/*");
427 | return intent;
428 | }
429 |
430 |
431 |
432 |
433 | }
434 | return null;
435 |
436 | }
437 |
438 |
439 |
440 | }
441 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tumuyan/fixedplay/SettingActivity.java:
--------------------------------------------------------------------------------
1 | package com.tumuyan.fixedplay;
2 |
3 | import android.Manifest;
4 | import android.app.Activity;
5 | import android.app.AlertDialog;
6 | import android.content.DialogInterface;
7 | import android.content.Intent;
8 | import android.content.SharedPreferences;
9 | import android.content.pm.ApplicationInfo;
10 | import android.content.pm.PackageManager;
11 | import android.graphics.drawable.Drawable;
12 | import android.os.Build;
13 | import android.os.Bundle;
14 | import android.util.Log;
15 | import android.view.View;
16 | import android.widget.CheckBox;
17 | import android.widget.EditText;
18 | import android.widget.ImageView;
19 | import android.widget.TextView;
20 | import android.widget.Toast;
21 |
22 | import com.tumuyan.fixedplay.App.SelectOne;
23 | import com.tumuyan.fixedplay.Beta.SelectApp;
24 |
25 | import java.util.ArrayList;
26 | import java.util.List;
27 | import java.util.Objects;
28 |
29 | public class SettingActivity extends Activity {
30 | PackageManager packageManager;
31 |
32 | String mode = "r2";
33 |
34 | String _mode = "";
35 | String _uri = "";
36 | String _action = "";
37 | String _data = "";
38 |
39 | int _intent_type = 0;
40 |
41 | TextView Text_PackageName;
42 | private View app_view_2nd;
43 |
44 | @Override
45 | protected void onCreate(Bundle savedInstanceState) {
46 | packageManager = getPackageManager();
47 |
48 | super.onCreate(savedInstanceState);
49 | setContentView(R.layout.activity_setting);
50 | Text_PackageName = (TextView) findViewById(R.id.text_pakageName);
51 | app_view_2nd = (View) findViewById(R.id.app_view_2nd);
52 | checkAndPermission();
53 | go();
54 | go2ndLauncher();
55 | findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
56 | @Override
57 | public void onClick(View view) {
58 |
59 | final String[] items3 = getResources().getStringArray(R.array.mode_main);
60 | // final String[] items3 = new String[]{"优先从后台切换到前台", "重新打开应用Activity", "浏览网页", "打开地图","拨打电话","打开文件","特定Activity","快捷方式","备用启动器"};//创建item
61 | AlertDialog alertDialog3 = new AlertDialog.Builder(SettingActivity.this)
62 | // .setTitle("选择任务模式")
63 | // .setIcon(R.mipmap.ic_launcher)
64 | .setItems(items3, new DialogInterface.OnClickListener() {//添加列表
65 | @Override
66 | public void onClick(DialogInterface dialogInterface, int i) {
67 | _mode = "";
68 | _uri = "";
69 | _action = "";
70 | _data = "";
71 | _intent_type = i;
72 | Intent select = new Intent(SettingActivity.this, SelectOne.class);
73 | switch (i) {
74 | case 0:
75 | _mode = "r2";
76 | select.putExtra("_mode", _mode);
77 | startActivity(select);
78 | break;
79 | case 1:
80 | _mode = "r1";
81 | select.putExtra("_mode", _mode);
82 | startActivity(select);
83 | break;
84 |
85 | case 2:
86 | _mode = "uri";
87 | inputUri(getString(R.string.title_hint_url), "http://m.baidu.com", "");
88 | break;
89 | case 3:
90 | _mode = "uri";
91 | inputUri(getString(R.string.title_hint_geo), "geo:38.899533,-77.036476", "geo:");
92 | break;
93 | case 4:
94 | // _mode="uri";
95 | _mode = "uri_dail";
96 | inputUri(getString(R.string.title_hint_tel), "tel:10086", "tel:");
97 | break;
98 |
99 | case 5:
100 | _mode = "uri_file";
101 | inputUri(getString(R.string.title_hint_file), "/sdcard/logs.txt", "");
102 | break;
103 | case 6:
104 | Intent i6 = new Intent(SettingActivity.this, SelectApp.class);
105 | startActivity(i6);
106 | break;
107 | case 8:
108 | select.putExtra("_mode", "2nd");
109 | startActivity(select);
110 | break;
111 | case 7:
112 | _mode = "short_cut";
113 | select.putExtra("_mode", _mode);
114 | startActivity(select);
115 | break;
116 |
117 | }
118 | }
119 | })
120 | .create();
121 | alertDialog3.show();
122 | }
123 | });
124 | findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() {
125 | @Override
126 | public void onClick(View view) {
127 |
128 | final String[] items3 = getResources().getStringArray(R.array.menu_delay);
129 | AlertDialog alertDialog3 = new AlertDialog.Builder(SettingActivity.this)
130 | .setTitle(R.string.delay_desc)
131 | // .setIcon(R.mipmap.ic_launcher)
132 | .setItems(items3, new DialogInterface.OnClickListener() {//添加列表
133 | @Override
134 | public void onClick(DialogInterface dialogInterface, int i) {
135 | switch (i) {
136 | case 0:
137 | configText(items3[i], TYPE_INT, "0", "splash_time");
138 | break;
139 | case 1:
140 | configText(items3[i], TYPE_STRING, "", "splash_img");
141 | break;
142 | }
143 | }
144 | })
145 | .create();
146 | alertDialog3.show();
147 | }
148 | });
149 |
150 | findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {
151 | @Override
152 | public void onClick(View v) {
153 |
154 | Intent intent = new Intent();
155 | intent.setClassName("com.android.settings",
156 | "com.android.settings.applications.DefaultAppSelectionActivity");
157 | intent.setAction("android.settings.HOME_SETTINGS");
158 |
159 | if (null == packageManager.resolveActivity(intent, 0)) {
160 | intent.setClassName("com.android.settings",
161 | "com.android.settings.Settings$AdvancedAppsActivity");
162 | Log.w("button1", "DefaultHomeSettings");
163 | }
164 |
165 |
166 | /* if(null==packageManager.resolveActivity(intent, 0)){
167 | intent = new Intent("com.miui.settings.HOME_SETTINGS_MIUI");
168 | intent.setClassName("com.android.settings",
169 | "com.android.settings.applications.DefaultHomeSettings");
170 | // intent.setAction("com.miui.settings.HOME_SETTINGS_MIUI");
171 | // miui.permission.USE_INTERNAL_GENERAL_API
172 |
173 | Log.w("button1","DefaultHomeSettings");
174 | }*/
175 |
176 | if (null != packageManager.resolveActivity(intent, 0)) {
177 | try {
178 | startActivity(intent);
179 | } catch (Exception e) {
180 | Log.w("button1", "creash");
181 | e.printStackTrace();
182 | Intent i = new Intent(Intent.ACTION_MAIN);
183 | i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
184 | i.addCategory(Intent.CATEGORY_HOME);
185 | startActivity(i);
186 | }
187 | } else {
188 | Log.w("button1", "not find");
189 | Intent i = new Intent(Intent.ACTION_MAIN);
190 | i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
191 | i.addCategory(Intent.CATEGORY_HOME);
192 | startActivity(i);
193 | }
194 | }
195 | });
196 |
197 | }
198 |
199 |
200 | public void inputUri(String title, String hint, final String prefix) {
201 | final EditText inputServer = new EditText(SettingActivity.this);
202 | inputServer.setHint(hint);
203 | final String fix;
204 | if (prefix == null) {
205 | fix = "";
206 | } else {
207 | fix = prefix.toLowerCase();
208 | }
209 | final AlertDialog.Builder builder = new AlertDialog.Builder(SettingActivity.this);
210 | builder.setTitle(title).
211 | setView(inputServer).
212 | setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
213 | @Override
214 | public void onClick(DialogInterface dialog, int which) {
215 | dialog.dismiss();
216 | }
217 | });
218 | builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
219 | public void onClick(DialogInterface dialog, int which) {
220 | _uri = inputServer.getText().toString().toLowerCase();
221 | Log.w("_uri", _uri);
222 | if (_uri.length() > 0) {
223 | String _sub_uri = _uri.substring(0, fix.length());
224 | if (_sub_uri.equals(prefix)) {
225 | _uri = fix + _uri.substring(fix.length());
226 | } else {
227 | _uri = fix + _uri;
228 | }
229 |
230 | Intent select = new Intent(SettingActivity.this, SelectOne.class);
231 | select.putExtra("_mode", _mode);
232 | select.putExtra("_uri", _uri);
233 | startActivity(select);
234 | }
235 | }
236 | }
237 | );
238 | builder.show();
239 | }
240 |
241 | static String TYPE_STRING = "String";
242 | static String TYPE_INT = "Integer";
243 |
244 | public void configText(String title, final String type, String default_value, final String key) {
245 | if (key.isEmpty()) {
246 | Log.e("configText()", "key is empty");
247 | return;
248 | }
249 | SharedPreferences read = getSharedPreferences("setting", MODE_MULTI_PROCESS);
250 | String value = "";
251 | if (Objects.equals(type, TYPE_STRING)) {
252 | value = read.getString(key, default_value);
253 | } else if (Objects.equals(type, TYPE_INT)) {
254 | value = String.valueOf(read.getInt(key, Integer.parseInt(default_value)));
255 | }
256 | final EditText inputServer = new EditText(SettingActivity.this);
257 | inputServer.setHint(default_value);
258 | inputServer.setText(value);
259 | inputServer.setSingleLine(true);
260 |
261 | final AlertDialog.Builder builder = new AlertDialog.Builder(SettingActivity.this);
262 | builder.setTitle(title).
263 | setView(inputServer).
264 | setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
265 | @Override
266 | public void onClick(DialogInterface dialog, int which) {
267 | dialog.dismiss();
268 | }
269 | });
270 | builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
271 | public void onClick(DialogInterface dialog, int which) {
272 | _uri = inputServer.getText().toString();
273 | Log.w("_uri", "key=" + key + ", value=" + _uri);
274 | SharedPreferences.Editor editor = SettingActivity.this.getSharedPreferences("setting", MODE_MULTI_PROCESS).edit();
275 | if (Objects.equals(TYPE_STRING, type)) {
276 | editor.putString(key, _uri);
277 | } else if (Objects.equals(type, TYPE_INT)) {
278 | editor.putInt(key, Integer.parseInt(_uri));
279 | }
280 | editor.commit();
281 | }
282 | }
283 | );
284 | builder.show();
285 | }
286 |
287 | @Override
288 | public void onResume() {
289 | super.onResume();
290 | go();
291 | go2ndLauncher();
292 | }
293 |
294 | public void go() {
295 | SharedPreferences read = getSharedPreferences("setting", MODE_MULTI_PROCESS);
296 |
297 | final String app = read.getString("app", "");
298 | if (app.length() < 1) return;
299 |
300 | mode = read.getString("mode", "r2");
301 | final String label = read.getString("label", "");
302 | final String uri = read.getString("uri", "");
303 | final String className = read.getString("class", "");
304 |
305 | final Drawable icon;
306 |
307 | try {
308 | ApplicationInfo appInfo = packageManager.getApplicationInfo(app, 0);
309 | icon = (appInfo.loadIcon(packageManager));
310 |
311 | runOnUiThread(new Runnable() {
312 | @Override
313 | public void run() {
314 | Text_PackageName.setText(label);
315 | //耗时操作,需要在子线程中完成操作后通知主线程实现UI更新
316 | String desc;
317 | if (uri.length() > 0) {
318 | desc = className + "\n" + uri;
319 | } else {
320 | desc = className;
321 | }
322 |
323 | ((ImageView) findViewById(R.id.item_img)).setImageDrawable(icon);
324 | ((TextView) findViewById(R.id.item_text)).setText(app);
325 | ((TextView) findViewById(R.id.item_packageName)).setText(desc);
326 | }
327 |
328 | });
329 | } catch (Exception e) {
330 | e.printStackTrace();
331 | }
332 |
333 |
334 | }
335 |
336 |
337 | public void go2ndLauncher() {
338 | SharedPreferences read = getSharedPreferences("setting", MODE_MULTI_PROCESS);
339 | boolean apply2nd = read.getBoolean("apply2nd", false);
340 | CheckBox cbx2ndLauncher = ((CheckBox) findViewById(R.id.cbx_2nd_launcher));
341 | cbx2ndLauncher.setChecked(apply2nd);
342 | cbx2ndLauncher.setOnClickListener(new View.OnClickListener() {
343 | @Override
344 | public void onClick(View view) {
345 | boolean state = ((CheckBox) view).isChecked();
346 | SharedPreferences.Editor editor = SettingActivity.this.getSharedPreferences("setting", MODE_MULTI_PROCESS).edit();
347 | editor.putBoolean("apply2nd", state);
348 | editor.commit();
349 | }
350 | });
351 |
352 | final String app = read.getString("app_2nd", "");
353 | if (app.length() < 1) return;
354 |
355 | final Drawable icon;
356 | final String label_2nd = read.getString("label_2nd", "");
357 | final String class_2nd = read.getString("class_2nd", "");
358 | Log.w("get 2nd", label_2nd + " - " + app + " - " + class_2nd);
359 | try {
360 | ApplicationInfo appInfo = packageManager.getApplicationInfo(app, 0);
361 | icon = (appInfo.loadIcon(packageManager));
362 |
363 | runOnUiThread(new Runnable() {
364 | @Override
365 | public void run() {
366 | ((ImageView) app_view_2nd.findViewById(R.id.item_img)).setImageDrawable(icon);
367 | ((TextView) app_view_2nd.findViewById(R.id.item_text)).setText(label_2nd);
368 | ((TextView) app_view_2nd.findViewById(R.id.item_packageName)).setText(app);
369 | app_view_2nd.setOnClickListener(new View.OnClickListener() {
370 | @Override
371 | public void onClick(View view) {
372 | Intent intent = packageManager.getLaunchIntentForPackage(app);
373 |
374 | if (intent != null) {
375 | // intent.setAction(Intent.ACTION_MAIN);
376 | // intent.addCategory("android.intent.category.HOME" );
377 | // intent.setAction(Intent.ACTION_VIEW);
378 | startActivity(intent);
379 | Log.i("go2ndLauncher", "intent not null");
380 | } else {
381 | // Toast.makeText(SettingActivity.this,R.string.error_could_not_start,Toast.LENGTH_SHORT).show();
382 |
383 | intent = new Intent();
384 | intent.setAction(Intent.ACTION_MAIN);
385 | if (class_2nd.length() > 5) {
386 | intent.setClassName(app, class_2nd);
387 | }
388 | try {
389 | startActivity(intent);
390 | } catch (Exception e) {
391 | e.printStackTrace();
392 | Toast.makeText(SettingActivity.this, R.string.error_could_not_start, Toast.LENGTH_SHORT).show();
393 | }
394 |
395 | Log.i("go2ndLauncher", "intent is null," + intent);
396 | }
397 |
398 | }
399 | });
400 | }
401 |
402 | });
403 | } catch (Exception e) {
404 | e.printStackTrace();
405 | }
406 |
407 | }
408 |
409 |
410 | private boolean isPkgInstalled(String packageName) {
411 | if (null == packageName)
412 | return false;
413 | if ((packageName).length() < 0)
414 | return false;
415 | android.content.pm.ApplicationInfo info;
416 | try {
417 | info = packageManager.getApplicationInfo(packageName, 0);
418 | return null != info;
419 | } catch (Exception e) {
420 | e.printStackTrace();
421 | }
422 | return false;
423 | }
424 |
425 |
426 | public void checkAndPermission() {
427 | Log.i("checkPermission", String.valueOf(Build.VERSION.SDK_INT));
428 | if (Build.VERSION.SDK_INT >= 23) {
429 | List lackedPermission = new ArrayList();
430 | // if (!(this.checkSelfPermission(Manifest.permission.READ_PHONE_STATE)== PackageManager.PERMISSION_GRANTED)) {
431 | // lackedPermission.add(Manifest.permission.READ_PHONE_STATE);
432 | // }
433 | if (!(this.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) {
434 | lackedPermission.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
435 | }
436 | // 权限都已经有了,那么直接调用SDK
437 | if (lackedPermission.size() == 0) {
438 | } else {
439 | // 请求所缺少的权限,在onRequestPermissionsResult中再看是否获得权限,如果获得权限就可以调用SDK,否则不要调用SDK。
440 | String[] requestPermissions = new String[lackedPermission.size()];
441 | lackedPermission.toArray(requestPermissions);
442 | this.requestPermissions(requestPermissions, 101);
443 | }
444 | }
445 | }
446 | }
447 |
--------------------------------------------------------------------------------