Example usage for android.content.pm PackageManager GET_META_DATA

List of usage examples for android.content.pm PackageManager GET_META_DATA

Introduction

In this page you can find the example usage for android.content.pm PackageManager GET_META_DATA.

Prototype

int GET_META_DATA

To view the source code for android.content.pm PackageManager GET_META_DATA.

Click Source Link

Document

ComponentInfo flag: return the ComponentInfo#metaData data android.os.Bundle s that are associated with a component.

Usage

From source file:com.ericsun.duom.DuoMApplication.java

public String addChannelId() {
    ApplicationInfo appInfo = null;/* w  w w.  j  ava  2 s  . com*/
    try {
        appInfo = getApplicationContext().getPackageManager()
                .getApplicationInfo(getApplicationContext().getPackageName(), PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    if (null != appInfo && null != appInfo.metaData) {
        return "" + appInfo.metaData.get("UMENG_CHANNEL");
    }
    return "";
}

From source file:com.sibext.android.activity.RedmineReportActivity.java

private void tryGetArgumentsFromManifest() {
    try {//w w  w  .  j  a  v a 2s .  c om
        ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(),
                PackageManager.GET_META_DATA);
        if (ai == null) {
            return;
        }
        redmineHost = ai.metaData.getString(getString(R.string.metadata_redmine_host));
        redmineKey = ai.metaData.getString(getString(R.string.metadata_redmine_key));
        redmineProject = ai.metaData.getString(getString(R.string.metadata_redmine_project));
        assigneeLogin = ai.metaData.getString(getString(R.string.metadata_redmine_assignee_login));
        Log.d(TAG, "tryGetArgumentsFromManifest");
    } catch (NameNotFoundException e) {
        Log.e(TAG, "Can't get init params", e);
    }
}

From source file:com.binil.pushnotification.ServerUtil.java

public static int getVersion(Context context) {
    int version = -1;
    try {/* w  w w  .ja va 2s  . com*/
        PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);
        version = pInfo.versionCode;

    } catch (NameNotFoundException e1) {
        Log.e(TAG, "Package Name not found", e1);
    }

    return version;
}

From source file:com.apexlabs.alarm.AlarmService.java

private Intent getClockIntent() {
    PackageManager packageManager = getPackageManager();
    Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);

    // Verify clock implementation
    String clockImpls[][] = {//w w  w.j  ava 2  s  .c  om
            { "HTC", "com.htc.android.worldclock", "com.htc.android.worldclock.WorldClockTabControl" },
            { "Standard", "com.android.deskclock", "com.android.deskclock.AlarmClock" },
            { "Froyo", "com.google.android.deskclock", "com.android.deskclock.DeskClock" },
            { "Motorola", "com.motorola.blur.alarmclock", "com.motorola.blur.alarmclock.AlarmClock" },
            { "Sony Ericsson", "com.sonyericsson.alarm", "com.sonyericsson.alarm.Alarm" }, { "Samsung",
                    "com.sec.android.app.clockpackage", "com.sec.android.app.clockpackage.ClockPackage" } };

    boolean foundClockImpl = false;

    for (int i = 0; i < clockImpls.length; i++) {
        String packageName = clockImpls[i][1];
        String className = clockImpls[i][2];
        try {
            ComponentName cn = new ComponentName(packageName, className);
            packageManager.getActivityInfo(cn, PackageManager.GET_META_DATA);
            alarmClockIntent.setComponent(cn);
            foundClockImpl = true;
            break;
        } catch (NameNotFoundException e) {
            Log.d(TAG, "Alarm clock " + clockImpls[i][0] + " not found");
        }
    }

    if (foundClockImpl) {
        alarmClockIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }
    return alarmClockIntent;
}

From source file:com.trk.aboutme.facebook.internal.Utility.java

public static String getMetadataApplicationId(Context context) {
    try {// w w w . j  av a2s.c o  m
        ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);
        if (ai.metaData != null) {
            return ai.metaData.getString(Session.APPLICATION_ID_PROPERTY);
        }
    } catch (PackageManager.NameNotFoundException e) {
        // if we can't find it in the manifest, just return null
    }

    return null;
}

From source file:com.dena.app.usage.watcher.service.WatchService.java

public void onCreate() {
    super.onCreate();
    try {/*  ww  w .j av a 2 s. c  om*/
        final PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(),
                PackageManager.GET_META_DATA);
        mTimer = new Timer(true);
        mTimer.scheduleAtFixedRate(new TimerTask() {
            @TargetApi(Build.VERSION_CODES.KITKAT)
            public void run() {
                if (WatchUtil.isScreenLocked(WatchService.this)) {
                    return;
                }
                try {
                    WatchDatabase db = ((App) getApplication()).getDatabase();
                    if (Build.VERSION_CODES.LOLLIPOP <= Build.VERSION.SDK_INT) {
                        AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
                        if (null != appOpsManager && AppOpsManager.MODE_ALLOWED != appOpsManager.checkOp(
                                AppOpsManager.OPSTR_GET_USAGE_STATS, packageInfo.applicationInfo.uid,
                                getPackageName())) {
                            Intent intent = new Intent(getApplicationContext(), DialogActivity.class);
                            intent.addFlags(WindowManager.LayoutParams.FLAG_LOCAL_FOCUS_MODE
                                    | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                            startActivity(intent);
                            return;
                        }
                    }
                    long time = System.currentTimeMillis();
                    String packageName = WatchUtil.getTopPackageName(WatchService.this);
                    if (null != packageName) {
                        db.addUsageAt(time, packageName);
                        db.addUsageAt(time);
                    }
                } catch (Exception e) {
                    Log.e(TAG, e.getMessage(), e);
                }
            }
        }, 0L, 1000L);
        startForeground(R.mipmap.ic_launcher, buildNotification());
    } catch (Exception e) {
        Log.e(TAG, e.getMessage(), e);
    }
}

From source file:com.onesignal.OSUtils.java

static String getManifestMeta(Context context, String metaName) {
    try {/*from   w  w w  .  jav  a2 s  .c  om*/
        ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);
        Bundle bundle = ai.metaData;
        return bundle.getString(metaName);
    } catch (Throwable t) {
        OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "", t);
    }

    return null;
}

From source file:com.echopf.ECHOInstallation.java

/**
 * Does Get registration id from the GCM server in a background thread.
 * //from   ww  w.j av  a2  s .  co m
 * @param sync if set TRUE, then the main (UI) thread is waited for complete the fetching in a background thread. 
 *              (a synchronous communication)
 * @param callback invoked after the getting is completed
 * @throws ECHOException 
 */
protected void doGetRegistrationId(final boolean sync, final InstallationCallback callback)
        throws ECHOException {
    // if(!checkPlayServices(ECHO.context)) return;

    // Get senderId from AndroidManifest.xml
    String senderId = null;
    try {
        ApplicationInfo appInfo = ECHO.context.getPackageManager()
                .getApplicationInfo(ECHO.context.getPackageName(), PackageManager.GET_META_DATA);
        senderId = appInfo.metaData.getString(GCM_SENDER_ID_KEY);
        senderId = (senderId.startsWith("id:")) ? senderId.substring(3) : null;
    } catch (NameNotFoundException ignored) {
        // skip
    }
    if (senderId == null)
        throw new RuntimeException("`" + GCM_SENDER_ID_KEY + "` is not specified in `AndroidManifest.xml`.");

    // Get ready a background thread
    final Handler handler = new Handler();
    final String fSenderId = senderId;

    ExecutorService executor = Executors.newSingleThreadExecutor();
    Callable<Object> communictor = new Callable<Object>() {

        @Override
        public Object call() throws ECHOException {
            ECHOException exception = null;

            // InstanceID instanceID = InstanceID.getInstance(ECHO.context);
            String token = null;

            // Get updated InstanceID token.
            token = FirebaseInstanceId.getInstance().getToken();
            // Log.d(TAG, "Refreshed token: " + refreshedToken);
            // TODO: Implement this method to send any registration to your app's servers.

            // token = instanceID.getToken(fSenderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE);
            synchronized (lock) {
                deviceToken = token;
            }

            if (sync == false) {

                // Execute a callback method in the main (UI) thread.
                final ECHOException fException = exception;
                final String fToken = token;

                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        ECHOInstallation.this.deviceToken = fToken;
                        callback.done(fException);
                    }
                });

            } else {

                if (exception != null)
                    throw exception;

            }

            return null;
        }
    };

    Future<Object> future = executor.submit(communictor);

    if (sync) {
        try {
            future.get();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt(); // ignore/reset
        } catch (ExecutionException e) {
            Throwable e2 = e.getCause();

            if (e2 instanceof ECHOException) {
                throw (ECHOException) e2;
            }

            throw new RuntimeException(e2);
        }
    }
}

From source file:org.runnerup.tracker.component.TrackerWear.java

@Override
public TrackerComponent.ResultCode onInit(final Callback callback, Context context) {
    this.context = context;
    if (!hasPlay()) {
        return ResultCode.RESULT_NOT_SUPPORTED;
    }/*from www.j  av  a 2s .c o m*/

    try {
        context.getPackageManager().getPackageInfo("com.google.android.wearable.app",
                PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException e) {
        // android wear app is not installed => can't be paired
        return ResultCode.RESULT_NOT_SUPPORTED;
    }

    tracker.registerTrackerStateListener(this);
    mGoogleApiClient = new GoogleApiClient.Builder(context)
            .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                @Override
                public void onConnected(Bundle connectionHint) {
                    callback.run(TrackerWear.this, ResultCode.RESULT_OK);

                    /* set "our" data */
                    setData();

                    Wearable.MessageApi.addListener(mGoogleApiClient, TrackerWear.this);
                    Wearable.NodeApi.addListener(mGoogleApiClient, TrackerWear.this);
                    Wearable.DataApi.addListener(mGoogleApiClient, TrackerWear.this);

                    /* read already existing data */
                    readData();

                    /** get info about connected nodes in background */
                    Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).

                            setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {

                                @Override
                                public void onResult(NodeApi.GetConnectedNodesResult nodes) {
                                    for (Node node : nodes.getNodes()) {
                                        onPeerConnected(node);
                                    }
                                }
                            }

            );
                }

                @Override
                public void onConnectionSuspended(int cause) {
                }
            }).addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
                @Override
                public void onConnectionFailed(ConnectionResult result) {
                    callback.run(TrackerWear.this, ResultCode.RESULT_ERROR);
                }
            }).addApi(Wearable.API).build();
    mGoogleApiClient.connect();
    return ResultCode.RESULT_PENDING;
}

From source file:com.oo58.game.texaspoker.AppActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //         this.getWindow().setFlags(FLAG_HOMEKEY_DISPATCHED, FLAG_HOMEKEY_DISPATCHED);//
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    mContext = AppActivity.this;

    try {/* w ww  .ja  v a  2 s  .c o  m*/
        ApplicationInfo appInfo = this.getPackageManager().getApplicationInfo(getPackageName(),
                PackageManager.GET_META_DATA);
        String msg = appInfo.metaData.getString("data_Name");

        //         int channelid = Integer.parseInt(msg) ;
        //         
        //         System.out.println(channelid);

    } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    mAct = this;
    allContext = this.getApplicationContext();
    mTencent = Tencent.createInstance("1104823392", getApplicationContext());
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "MyLock");
    mWakeLock.acquire();

    MobclickAgent.setDebugMode(false);
    MobclickAgent.updateOnlineConfig(this);
    AnalyticsConfig.enableEncrypt(true);

    checkUpdate();

    PackageManager pm2 = getPackageManager();
    homeInfo = pm2.resolveActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME), 0);

    mNetChecker.initAndRegListener(mContext);

    mWXPay.init(this);

    MobClickCppHelper.init(this);

    //      // logcatdebug
    //       XGPushConfig.enableDebug(this, true);
    //      // registerPush(getApplicationContext(), XGIOperateCallback)callback
    //      // registerPush(getApplicationContext(),account)
    //      // 
    //      // ApplicationContext
    //      Context context = getApplicationContext();
    //      XGPushManager.registerPush(context);    
    //       
    //      // 2.362
    //      Intent service = new Intent(context, XGPushService.class);
    //      context.startService(service);

    // API
    // registerPush(context,account)registerPush(context,account, XGIOperateCallback)accountAPPqqopenid
    // registerPush(context,"*")account="*"
    // unregisterPush(context)
    // setTag(context, tagName)
    // deleteTag(context, tagName)

    updateListViewReceiver = new MsgReceiver();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction("com.oo58.game.texaspoker.activity.UPDATE_LISTVIEW");
    registerReceiver(updateListViewReceiver, intentFilter);

    XGPushManager.registerPush(getApplicationContext(), new XGIOperateCallback() {
        @Override
        public void onSuccess(Object data, int flag) {
            //                  Log.w(Constants.LogTag,
            //                        "+++ register push sucess. token:" + data);

        }

        @Override
        public void onFail(Object data, int errCode, String msg) {
            //                  Log.w(Constants.LogTag,
            //                        "+++ register push fail. token:" + data
            //                              + ", errCode:" + errCode + ",msg:"
            //                              + msg);

        }
    });

    //javajosnC++demo
    /*      JSONObject jsonObj = new JSONObject();  
            try {
             jsonObj.put("Int_att",25);
               jsonObj.put("String_att","str");//string  
               jsonObj.put("Double_att",12.25);//double  
               jsonObj.put("Boolean_att",true);//boolean  
          } catch (JSONException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
          }//int  
            
            PushJson(jsonObj.toString()) ;*/

}