2013-04-05 22 views
8

Cyanogenmod ROMは焼き付けられたプロファイルをサポートしていますが、これがデフォルトのAndroid機能の一部であるかわかりませんが、現在選択されているプロファイルの名前を取得できるかどうかは疑問でした。電話機の現在選択されているプロファイルを取得することはできますか?

これに関する開発者向けドキュメントは見つかりませんでした。

(AndroidのSDKがこれをサポートしていないと仮定すると、スーパーユーザのアプリがこの機能を実装することができますか?)

おかげで、私はProfileManagerのソースコードを発見したいくつかのCMソースから重そうに歩く


。メソッドは公開されているので、私はJavaのリフレクションのウサギの穴を塞ぐ必要はありませんが、これらのクラスを使用するには、Cyanogenmod JARが必要です。

答えて

0

醜い反射と浮遊感のビット。クラスはProfileManagerProfile

Object o = getSystemService("profile"); 
    try { 

     Class<?> ProfileManager = Class.forName("android.app.ProfileManager"); 
     Class<?> Profile = Class.forName("android.app.Profile"); 
     try { 

      Method getActiveProfile = ProfileManager.getDeclaredMethod("getActiveProfile", null); 
      Method getName = Profile.getDeclaredMethod("getName", null); 

      try { 

       String strProfile = (String) getName.invoke(getActiveProfile.invoke(o)); 
       System.out.println("Current profile is: " + strProfile); 

      } catch (IllegalAccessException e) { 
       e.printStackTrace(); 
      } catch (InvocationTargetException e) { 
       e.printStackTrace(); 
      } 

     } catch (NoSuchMethodException e) { 
      e.printStackTrace(); 
     }   

    } catch (ClassNotFoundException e) { 
     e.printStackTrace(); 
    } 
です
関連する問題