相机和图库具有相同的包名称

时间:2016-08-25 06:09:39

标签: android camera gallery launcher

我正在开发一个Launcher应用程序。我注意到相机和图库具有相同的包名,同时Google+和照片具有相同的包名称。当我尝试启动相机/图库时,它会打开图库,当我尝试启动Photos / Google +时,我会打开Goog​​le +。

我正在使用此代码获取应用列表。

Intent i = new Intent(Intent.ACTION_MAIN, null);
i.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> availableActivities = manager.queryIntentActivities(i, 0);

至于相机,我知道当应用名称为相机时,我可以使用Intent启动相机,包名称是图库的名称,但可能有许多相同的应用程序。是否有适用于所有应用的通用解决方案?

P.S。:这就是我获取应用信息的方式

for(ResolveInfo ri : availableActivities) {
    AppItem app = new AppItem();
    app.setLabel(ri.loadLabel(manager));
    app.setName(ri.activityInfo.packageName);
    quick_apps.add(app);
}

1 个答案:

答案 0 :(得分:1)

虽然它们具有相同的包名,但它们具有不同的名称,请尝试此操作以启动您的活动,使用以下代码开始活动

           /// I use RESTUtility and i've tried to adapt this code : http://www.programcreek.com/java-api-examples/index.php?api=com.dropbox.client2.RESTUtility
           /// example  : 8 for last_cursor
           /// example : 13 for longpoll_delta

           /// https://www.dropbox.com/developers-v1/core/docs#delta
           // we use first the method : /delta/latest_cursor to get a cursor

           Log.d(" NotificationService", " ================================Finding latest cursor");
           ArrayList<String> params = new ArrayList<>();
           params.add("include_media_info");
           params.add("false"); // if true there is a mistake
           Object response = RESTUtility.request(RESTUtility.RequestMethod.POST, "api.dropbox.com", "delta/latest_cursor", 1, params.toArray(new String[params.size()]), mDBApi.getSession());

           /// Preparation of the cursor to use longpoll_ delta

           // response.toString() look like that : {"cursor":"AAGwyo3TijR4_dgBxCj8LrU-NBO5ET7xipVxMl_vGMn-O7PKemycTBR3FpK57856J-vTtn5wyNyzwJaaGlKn2h2o5gv8lBFzQ6Hn9KgdDHi7uH77boLG2Y1GOT1VgnWyxMU"}
           Log.d(" NotificationService", " ================================First cursor avant le substring : " + response.toString());
           // lastestCursor look lije that : AAGwyo3TijR4_dgBxCj8LrU-NBO5ET7xipVxMl_vGMn-O7PKemycTBR3FpK57856J-vTtn5wyNyzwJaaGlKn2h2o5gv8lBFzQ6Hn9KgdDHi7uH77boLG2Y1GOT1VgnWyxMU
           latestCursor = response.toString().substring(11, response.toString().length() - 2);
           Log.d(" NotificationService", " ================================First cursor: " + latestCursor);

           //Try to use longpoll_delta to know if {"changes": false, "backoff": 60} changes is true

           ArrayList<String> paramsLongpoll_delta = new ArrayList<>();
           paramsLongpoll_delta.add("cursor");
           paramsLongpoll_delta.add(latestCursor);
           paramsLongpoll_delta.add("timeout");
           paramsLongpoll_delta.add("120");

           Object responseLongpoll_delta = RESTUtility.request(RESTUtility.RequestMethod.GET, "api-notify.dropbox.com", "longpoll_delta", 1, paramsLongpoll_delta.toArray(new String[paramsLongpoll_delta.size()]), mDBApi.getSession());
           Log.d(" NotificationService", " ================================Second Cursor: " + responseLongpoll_delta.toString());

        } catch (DropboxException e1) {
            e1.printStackTrace();
        }
    }
});
interrogateTheServerTask.start();