当前位置: 首页>>代码示例>>Java>>正文


Java Context.getPackageName方法代码示例

本文整理汇总了Java中android.content.Context.getPackageName方法的典型用法代码示例。如果您正苦于以下问题:Java Context.getPackageName方法的具体用法?Java Context.getPackageName怎么用?Java Context.getPackageName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.Context的用法示例。


在下文中一共展示了Context.getPackageName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isAppOnForeground

import android.content.Context; //导入方法依赖的package包/类
@SuppressLint({"NewApi"})
public static boolean isAppOnForeground(Context mContext) {
    ActivityManager activityManager = (ActivityManager) mContext.getSystemService("activity");
    String packageName = mContext.getPackageName();
    LogInfo.log("PushReceiver", "packageName =" + packageName);
    List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
    if (appProcesses == null) {
        LogInfo.log("PushReceiver", "------appProcesses == null-----");
        return false;
    }
    for (RunningAppProcessInfo appProcess : appProcesses) {
        LogInfo.log("PushReceiver", "------appProcess.processName =" + appProcess.processName);
        if (appProcess.processName.equals(packageName) && appProcess.importance == 100) {
            for (RunningTaskInfo rti : activityManager.getRunningTasks(100)) {
                if (!(rti == null || rti.baseActivity == null || mContext.getPackageName() == null || !mContext.getPackageName().equals(rti.baseActivity.getPackageName()) || VERSION.SDK_INT < 11)) {
                    activityManager.moveTaskToFront(rti.id, 1);
                }
            }
            return true;
        }
    }
    return false;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:24,代码来源:PushNotificationReceiver.java

示例2: checkIfServiceIsRunning

import android.content.Context; //导入方法依赖的package包/类
public static boolean checkIfServiceIsRunning(Context context, Class<?> service) {

        String serviceName = service.getName();

        ComponentName componentName = new ComponentName(context.getPackageName(), serviceName);

        ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

        List<ActivityManager.RunningServiceInfo> procList = activityManager.getRunningServices(Integer.MAX_VALUE);

        if (procList != null) {

            for (ActivityManager.RunningServiceInfo appProcInfo : procList) {
                if (appProcInfo != null && componentName.equals(appProcInfo.service)) {
                    log.d("%s is already running", serviceName);
                    return true;
                }
            }
        }
        log.d("%s is not running", serviceName);
        return false;
    }
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:23,代码来源:ServiceHelper.java

示例3: getVersionName

import android.content.Context; //导入方法依赖的package包/类
/**
 * Merges app name and version name into one.
 */
public static CharSequence getVersionName(Context context) {
    PackageManager pm = context.getPackageManager();
    String packageName = context.getPackageName();
    String versionName;
    try {
        PackageInfo info = pm.getPackageInfo(packageName, 0);
        versionName = info.versionName;

        // Make the info part of version name a bit smaller.
        if (versionName.indexOf('-') >= 0) {
            versionName = versionName.replaceFirst("\\-", "<small>-") + "</small>";
        }
    } catch (PackageManager.NameNotFoundException e) {
        versionName = VERSION_UNAVAILABLE;
    }

    Resources res = context.getResources();
    return Html.fromHtml(
            res.getString(R.string.about_title,
                    res.getString(R.string.nome_app_turbo_editor), versionName)
    );
}
 
开发者ID:ujjwalagrawal17,项目名称:CodeCompilerApp,代码行数:26,代码来源:AboutDialog.java

示例4: getIconResId

import android.content.Context; //导入方法依赖的package包/类
/**
 * Retrieves the resource ID of the app icon.
 *
 * @param settings A JSON dict containing the icon name.
 */
private int getIconResId(JSONObject settings) {
    Context context = getApplicationContext();
    Resources res   = context.getResources();
    String pkgName  = context.getPackageName();
    String icon     = settings.optString("icon", NOTIFICATION_ICON);

    // cordova-android 6 uses mipmaps
    int resId = getIconResId(res, icon, "mipmap", pkgName);

    if (resId == 0) {
        resId = getIconResId(res, icon, "drawable", pkgName);
    }

    return resId;
}
 
开发者ID:SUTFutureCoder,项目名称:localcloud_fe,代码行数:21,代码来源:ForegroundService.java

示例5: testProviderRegistry

import android.content.Context; //导入方法依赖的package包/类
@Test
public void testProviderRegistry() {
    Context appContext = InstrumentationRegistry.getTargetContext();
    PackageManager pm = appContext.getPackageManager();

    // We define the component name based on the package name from the context and the
    // Provider class.
    ComponentName componentName = new ComponentName(appContext.getPackageName(),
            FavoritesProvider.class.getName());
    try {
        // Fetch the provider info using the component name from the PackageManager
        // This throws an exception if the provider isn't registered.
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);

        // Make sure that the registered authority matches the authority from the Contract.
        assertEquals("Error: FavoritesProvider registered with authority: " + providerInfo.authority
                + " instead of authority: " + FavoritesContract.AUTHORITY,
                providerInfo.authority, FavoritesContract.AUTHORITY);
    } catch (PackageManager.NameNotFoundException e) {
        // I guess the provider isn't registered correctly.
        assertTrue("Error: FavoritesProvider not registered at " + appContext.getPackageName(),
                false);
    }
}
 
开发者ID:an-garcia,项目名称:MovieGuide,代码行数:25,代码来源:TestProvider.java

示例6: jumpMarket

import android.content.Context; //导入方法依赖的package包/类
public static void jumpMarket(Context mContext, String packageName) {
    if (mContext == null) {
        return;
    }
    if (packageName == null || packageName.isEmpty()) {
        packageName = mContext.getPackageName();
    }
    String mAddress = "market://details?id=" + packageName;
    try {
        Intent marketIntent = new Intent("android.intent.action.VIEW");
        marketIntent.setData(Uri.parse(mAddress));
        mContext.startActivity(marketIntent);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:AriesHoo,项目名称:TitleBarView,代码行数:17,代码来源:AppUtil.java

示例7: HostManager

import android.content.Context; //导入方法依赖的package包/类
protected HostManager(Context context, HostFilter hostFilter, HttpGet httpGet, String str,
                      String str2, String str3) {
    this.sAppContext = context.getApplicationContext();
    if (this.sAppContext == null) {
        this.sAppContext = context;
    }
    this.sHttpGetter = httpGet;
    if (hostFilter == null) {
        this.sHostFilter = new b(this);
    } else {
        this.sHostFilter = hostFilter;
    }
    this.sUserId = str;
    if (str2 == null) {
        str2 = context.getPackageName();
    }
    sAppName = str2;
    if (str3 == null) {
        str3 = getVersionName();
    }
    sAppVersion = str3;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:23,代码来源:HostManager.java

示例8: getFullClassName

import android.content.Context; //导入方法依赖的package包/类
private String getFullClassName(Context context, String className) {
    if (className.charAt(0) == '.') {
        return context.getPackageName() + className;
    }
    if (className.indexOf('.') != -1) {
        return className;
    }
    return RecyclerView.class.getPackage().getName() + '.' + className;
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:10,代码来源:RecyclerView.java

示例9: onUpdate

import android.content.Context; //导入方法依赖的package包/类
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    // update each of the widgets with the remote adapter
    for (int i = 0; i < appWidgetIds.length; ++i) {

        // Here we setup the intent which points to the StackViewService which will
        // provide the views for this collection.
        Intent intent = new Intent(context, StackWidgetService.class);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
        // When intents are compared, the extras are ignored, so we need to embed the extras
        // into the data so that the extras will not be ignored.
        intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
        RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
        rv.setRemoteAdapter(appWidgetIds[i], R.id.stack_view, intent);

        // The empty view is displayed when the collection has no items. It should be a sibling
        // of the collection view.
        rv.setEmptyView(R.id.stack_view, R.id.empty_view);

        // Here we setup the a pending intent template. Individuals items of a collection
        // cannot setup their own pending intents, instead, the collection as a whole can
        // setup a pending intent template, and the individual items can set a fillInIntent
        // to create unique before on an item to item basis.
        Intent toastIntent = new Intent(context, StackWidgetProvider.class);
        toastIntent.setAction(StackWidgetProvider.TOAST_ACTION);
        toastIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
        intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
        PendingIntent toastPendingIntent = PendingIntent.getBroadcast(context, 0, toastIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        rv.setPendingIntentTemplate(R.id.stack_view, toastPendingIntent);

        appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
    }
    super.onUpdate(context, appWidgetManager, appWidgetIds);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:36,代码来源:StackWidgetProvider.java

示例10: newRequestQueue

import android.content.Context; //导入方法依赖的package包/类
/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

    String userAgent = "volley/0";
    try {
        String packageName = context.getPackageName();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }

    if (stack == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            stack = new HurlStack();
        } else {
            // Prior to Gingerbread, HttpUrlConnection was unreliable.
            // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
            stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
        }
    }

    Network network = new BasicNetwork(stack);

    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
    queue.start();

    return queue;
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:36,代码来源:Volley.java

示例11: updateAppWidgetLayout

import android.content.Context; //导入方法依赖的package包/类
private static void updateAppWidgetLayout(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
    Filter filter = getFilter(context, appWidgetId);

    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.list_widget);

    Intent serviceIntent = new Intent(context, ListWidgetService.class);
    serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    serviceIntent.putExtra(AppIntent.EXTRA_QUERY_STRING, filter.getQuery());
    serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));

    // Tell ListView where to get the data from
    remoteViews.setRemoteAdapter(R.id.list_widget_list_view, serviceIntent);

    remoteViews.setEmptyView(R.id.list_widget_list_view, R.id.list_widget_empty_view);
    if (filter.getQuery() == null) {
        remoteViews.setTextViewText(R.id.list_widget_empty_view, context.getString(R.string.select_a_filter_long));
    } else {
        remoteViews.setTextViewText(R.id.list_widget_empty_view, context.getString(R.string.no_notes_found_after_search));
    }

    // Rows - open note
    final Intent onClickIntent = new Intent(context, ListWidgetProvider.class);
    onClickIntent.setAction(AppIntent.ACTION_CLICK_LIST_WIDGET);
    onClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    onClickIntent.setData(Uri.parse(onClickIntent.toUri(Intent.URI_INTENT_SCHEME)));
    final PendingIntent onClickPendingIntent = PendingIntent.getBroadcast(context, 0,
            onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setPendingIntentTemplate(R.id.list_widget_list_view, onClickPendingIntent);

    // Plus icon - new note
    remoteViews.setOnClickPendingIntent(R.id.list_widget_header_add, ShareActivity.createNewNoteIntent(context, filter));

    // Logo - open query
    Intent openIntent = Intent.makeRestartActivityTask(new ComponentName(context, MainActivity.class));
    openIntent.putExtra(AppIntent.EXTRA_QUERY_STRING, filter.getQuery());
    serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setOnClickPendingIntent(R.id.list_widget_header_icon, PendingIntent.getActivity(context, 0, openIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    Intent filterSelectIntent = new Intent(context, FilterSelectDialogActivity.class);
    filterSelectIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    filterSelectIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setOnClickPendingIntent(R.id.list_widget_header_bar, PendingIntent.getActivity(context, 0, filterSelectIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    remoteViews.setTextViewText(
            R.id.list_widget_header_filter,
            filter.getName());

    appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:50,代码来源:ListWidgetProvider.java

示例12: onReceive

import android.content.Context; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);
    MonolithWidget.intent = intent;
    Log.d(TAG, "onReceive is called");
    if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(intent.getAction())) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        int[] appWidgetIds = appWidgetManager.getAppWidgetIds(
                new ComponentName(context, getClass()));
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.monolith_widget);
        appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.widget_list);
    }

    if (intent.getAction().equals(ACTION_WIDGET_CLICK)) {
        Log.e(TAG, "onReceive: Intent has ACTION_WIDGET_CLICK");
        Bundle bundle = new Bundle();
        bundle.putString(context.getResources().getString(R.string.title), intent.getStringExtra(context.getResources().getString(R.string.title)));
        bundle.putString(context.getResources().getString(R.string.date), intent.getStringExtra("date"));
        bundle.putString(context.getResources().getString(R.string.image), intent.getStringExtra("image"));
        bundle.putString(context.getResources().getString(R.string.description), intent.getStringExtra("description"));
        bundle.putString(context.getResources().getString(R.string.link), intent.getStringExtra(context.getResources().getString(R.string.link)));
        Intent intent1 = new Intent(context, ArticleDetailActivity.class);
        intent1.putExtras(bundle);
        intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent1);
    }
}
 
开发者ID:prshntpnwr,项目名称:Monolith,代码行数:29,代码来源:MonolithWidget.java

示例13: makeNotification

import android.content.Context; //导入方法依赖的package包/类
/**
 * Create a notification as the visible part to be able to put the service
 * in a foreground state.
 *
 * @param settings The config settings
 */
private Notification makeNotification(JSONObject settings) {
    String title    = settings.optString("title", NOTIFICATION_TITLE);
    String text     = settings.optString("text", NOTIFICATION_TEXT);
    boolean bigText = settings.optBoolean("bigText", false);

    Context context = getApplicationContext();
    String pkgName  = context.getPackageName();
    Intent intent   = context.getPackageManager()
            .getLaunchIntentForPackage(pkgName);

    Notification.Builder notification = new Notification.Builder(context)
            .setContentTitle(title)
            .setContentText(text)
            .setOngoing(true)
            .setSmallIcon(getIconResId(settings));

    if (settings.optBoolean("hidden", true)) {
        notification.setPriority(Notification.PRIORITY_MIN);
    }

    if (bigText || text.contains("\n")) {
        notification.setStyle(
                new Notification.BigTextStyle().bigText(text));
    }

    setColor(notification, settings);

    if (intent != null && settings.optBoolean("resume")) {
        PendingIntent contentIntent = PendingIntent.getActivity(
                context, NOTIFICATION_ID, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        notification.setContentIntent(contentIntent);
    }

    return notification.build();
}
 
开发者ID:SUTFutureCoder,项目名称:localcloud_fe,代码行数:44,代码来源:ForegroundService.java

示例14: getVersionCode

import android.content.Context; //导入方法依赖的package包/类
/**
 * A utility method to get the application's PackageInfo.versionCode
 * @return the application's PackageInfo.versionCode
 */
public static int getVersionCode(final Context context) {
    try {
        if (context == null) {
            return 0;
        }
        final String packageName = context.getPackageName();
        final PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        return info.versionCode;
    } catch (final NameNotFoundException e) {
        Log.e(TAG, "Could not find version info.", e);
    }
    return 0;
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:18,代码来源:ApplicationUtils.java

示例15: updateAppWidget

import android.content.Context; //导入方法依赖的package包/类
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
                            int appWidgetId) {

    setCountersDK(context);
    setCountersIO(context);
    setCountersFromPreferences(context);

    // Construct the RemoteViews object
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.kaem_widget);
    views.setTextViewText(R.id.dk_kaem_users, dkUsersCount);
    views.setTextViewText(R.id.dk_kaem_projects, dkProjectsCount);
    views.setTextViewText(R.id.dk_kaem_teams, dkTeamsCount);
    views.setTextViewText(R.id.dk_kaem_lookups, dkLookupsCount);

    views.setTextViewText(R.id.io_kaem_users, ioUsersCount);
    views.setTextViewText(R.id.io_kaem_projects, ioProjectsCount);
    views.setTextViewText(R.id.io_kaem_teams, ioTeamsCount);
    views.setTextViewText(R.id.io_kaem_lookups, ioLookupsCount);

    // Pending intent for refresh button
    Intent intent = new Intent(REFRESH_BUTTON);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    views.setOnClickPendingIntent(R.id.REFRESH_BUTTON, pendingIntent);

    // Instruct the widget manager to update the widget
    appWidgetManager.updateAppWidget(appWidgetId, views);
}
 
开发者ID:KAEM,项目名称:android-widget,代码行数:28,代码来源:KaemWidget.java


注:本文中的android.content.Context.getPackageName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。