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


Java Activity.getPackageName方法代码示例

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


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

示例1: launch

import android.app.Activity; //导入方法依赖的package包/类
@Override public void launch(Activity activity) {
  RemoteViews remoteViews =
      new RemoteViews(activity.getPackageName(), R.layout.notification_view);

  Intent intent = new Intent(activity, SampleGridViewActivity.class);

  NotificationCompat.Builder builder =
      new NotificationCompat.Builder(activity).setSmallIcon(R.drawable.icon)
          .setContentIntent(PendingIntent.getActivity(activity, -1, intent, 0))
          .setContent(remoteViews);

  Notification notification = builder.getNotification();

  NotificationManager notificationManager =
      (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
  notificationManager.notify(NOTIFICATION_ID, notification);

  // Now load an image for this notification.
  Picasso.with() //
      .load(Data.URLS[new Random().nextInt(Data.URLS.length)]) //
      .resizeDimen(R.dimen.notification_icon_width_height,
          R.dimen.notification_icon_width_height) //
      .into(remoteViews, R.id.photo, NOTIFICATION_ID, notification);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:PicassoSampleAdapter.java

示例2: sendChooserIntent

import android.app.Activity; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
static void sendChooserIntent(boolean saveLastUsed, Activity activity,
                              Intent sharingIntent,
                              @Nullable TargetChosenCallback callback) {
    synchronized (LOCK) {
        if (sTargetChosenReceiveAction == null) {
            sTargetChosenReceiveAction = activity.getPackageName() + "/"
                    + TargetChosenReceiver.class.getName() + "_ACTION";
        }
        Context context = activity.getApplicationContext();
        if (sLastRegisteredReceiver != null) {
            context.unregisterReceiver(sLastRegisteredReceiver);
            // Must cancel the callback (to satisfy guarantee that exactly one method of
            // TargetChosenCallback is called).
            // TODO(mgiuca): This should be called immediately upon cancelling the chooser,
            // not just when the next share takes place (https://crbug.com/636274).
            sLastRegisteredReceiver.cancel();
        }
        sLastRegisteredReceiver = new TargetChosenReceiver(saveLastUsed, callback);
        context.registerReceiver(
                sLastRegisteredReceiver, new IntentFilter(sTargetChosenReceiveAction));
    }

    Intent intent = new Intent(sTargetChosenReceiveAction);
    intent.setPackage(activity.getPackageName());
    intent.putExtra(EXTRA_RECEIVER_TOKEN, sLastRegisteredReceiver.hashCode());
    final PendingIntent pendingIntent = PendingIntent.getBroadcast(activity, 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
    Intent chooserIntent = Intent.createChooser(sharingIntent,
            activity.getString(R.string.share_link_chooser_title),
            pendingIntent.getIntentSender());
    if (sFakeIntentReceiverForTesting != null) {
        sFakeIntentReceiverForTesting.setIntentToSendBack(intent);
    }
    fireIntent(activity, chooserIntent);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:37,代码来源:ShareHelper.java

示例3: openPlayStorePage

import android.app.Activity; //导入方法依赖的package包/类
public static void openPlayStorePage(Activity activity){

        String appPackageName = activity.getPackageName();
        try {
            activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
        } catch (android.content.ActivityNotFoundException anfe) {
            activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
        }
    }
 
开发者ID:adriankeenan,项目名称:uob-timetable-android,代码行数:10,代码来源:AndroidUtilities.java

示例4: initExceptionHandler

import android.app.Activity; //导入方法依赖的package包/类
public static void initExceptionHandler(Activity activity, String appName, String userName) {
	final File traceFile = new File(activity.getFilesDir(), "rxtrace.log");
	if (traceFile.exists()) {
		try {
			String trace = Utils.loadString(traceFile);
			traceFile.delete();
			sendTrace(activity, appName, userName, trace);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
	final String packageName = activity.getPackageName();

	final Thread.UncaughtExceptionHandler oldHandler =
            Thread.getDefaultUncaughtExceptionHandler();

	Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
		public void uncaughtException(Thread thread, Throwable throwable) {
			if (throwable != null) {
				saveTrace(traceFile, throwable, packageName);
				throwable.printStackTrace();
				if (oldHandler!=null) {
            		oldHandler.uncaughtException(thread, throwable);
            	} else {
					android.os.Process.killProcess(android.os.Process.myPid());
					System.exit(0);
                }
			}
		}
	});
}
 
开发者ID:fcatrin,项目名称:retroxlibs,代码行数:34,代码来源:RetroBoxUtils.java

示例5: moveToForeground

import android.app.Activity; //导入方法依赖的package包/类
/**
 * Move app to foreground.
 */
private void moveToForeground() {
    Activity    app = getActivity();
    String pkgName  = app.getPackageName();

    Intent intent = app
            .getPackageManager()
            .getLaunchIntentForPackage(pkgName);

    intent.addFlags(  Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    app.startActivity(intent);
}
 
开发者ID:SUTFutureCoder,项目名称:localcloud_fe,代码行数:17,代码来源:BackgroundExt.java

示例6: requestSystemAlertPermission

import android.app.Activity; //导入方法依赖的package包/类
/**
 * @param fragment
 * @param requestCode
 */
public void requestSystemAlertPermission(Activity context, Fragment fragment, int requestCode) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
        return;
    final String packageName = context == null ? fragment.getActivity().getPackageName() : context.getPackageName();
    final Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + packageName));
    if (fragment != null)
        fragment.startActivityForResult(intent, requestCode);
    else
        context.startActivityForResult(intent, requestCode);
}
 
开发者ID:tatocaster,项目名称:BuildNumberOverlay,代码行数:15,代码来源:AccessPermissionActivity.java

示例7: getVersion

import android.app.Activity; //导入方法依赖的package包/类
private String getVersion() {
    try {
        Activity activity = getActivity();
        String packageName = activity.getPackageName();
        PackageInfo packageInfo = activity.getPackageManager().getPackageInfo(packageName, 0);
        //return packageInfo.versionName;
        return "4.5.1";
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "getVersion: error", e);
        return "1.0";
    }
}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:13,代码来源:AboutSettingsFragment.java

示例8: initialize

import android.app.Activity; //导入方法依赖的package包/类
@Override
 public void initialize(CordovaInterface cordova, CordovaWebView webView) {
 	super.initialize(cordova, webView);
 	this.filesystems = new ArrayList<Filesystem>();
     this.pendingRequests = new PendingRequests();

 	String tempRoot = null;
 	String persistentRoot = null;

 	Activity activity = cordova.getActivity();
 	String packageName = activity.getPackageName();

     String location = preferences.getString("androidpersistentfilelocation", "internal");

 	tempRoot = activity.getCacheDir().getAbsolutePath();
 	if ("internal".equalsIgnoreCase(location)) {
 		persistentRoot = activity.getFilesDir().getAbsolutePath() + "/files/";
 		this.configured = true;
 	} else if ("compatibility".equalsIgnoreCase(location)) {
 		/*
 		 *  Fall-back to compatibility mode -- this is the logic implemented in
 		 *  earlier versions of this plugin, and should be maintained here so
 		 *  that apps which were originally deployed with older versions of the
 		 *  plugin can continue to provide access to files stored under those
 		 *  versions.
 		 */
 		if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
 			persistentRoot = Environment.getExternalStorageDirectory().getAbsolutePath();
 			tempRoot = Environment.getExternalStorageDirectory().getAbsolutePath() +
 					"/Android/data/" + packageName + "/cache/";
 		} else {
 			persistentRoot = "/data/data/" + packageName;
 		}
 		this.configured = true;
 	}

 	if (this.configured) {
// Create the directories if they don't exist.
File tmpRootFile = new File(tempRoot);
         File persistentRootFile = new File(persistentRoot);
         tmpRootFile.mkdirs();
         persistentRootFile.mkdirs();

 		// Register initial filesystems
 		// Note: The temporary and persistent filesystems need to be the first two
 		// registered, so that they will match window.TEMPORARY and window.PERSISTENT,
 		// per spec.
 		this.registerFilesystem(new LocalFilesystem("temporary", webView.getContext(), webView.getResourceApi(), tmpRootFile));
 		this.registerFilesystem(new LocalFilesystem("persistent", webView.getContext(), webView.getResourceApi(), persistentRootFile));
 		this.registerFilesystem(new ContentFilesystem(webView.getContext(), webView.getResourceApi()));
         this.registerFilesystem(new AssetFilesystem(webView.getContext().getAssets(), webView.getResourceApi()));

         registerExtraFileSystems(getExtraFileSystemsPreference(activity), getAvailableFileSystems(activity));

 		// Initialize static plugin reference for deprecated getEntry method
 		if (filePlugin == null) {
 			FileUtils.filePlugin = this;
 		}
 	} else {
 		LOG.e(LOG_TAG, "File plugin configuration error: Please set AndroidPersistentFileLocation in config.xml to one of \"internal\" (for new applications) or \"compatibility\" (for compatibility with previous versions)");
 		activity.finish();
 	}
 }
 
开发者ID:alex-shpak,项目名称:keemob,代码行数:64,代码来源:FileUtils.java

示例9: License

import android.app.Activity; //导入方法依赖的package包/类
public License(Activity activity) {
	String deviceId = Secure.getString(activity.getContentResolver(), Secure.ANDROID_ID);
	licenseCallback = new BlueWatcherLicenseCheckerCallback(activity);
	licenseChecker = new LicenseChecker(activity, new ServerManagedPolicy(activity, new AESObfuscator(License.SALT, activity.getPackageName(),
			deviceId)), License.APP_PUBLIC_KEY);
}
 
开发者ID:masterjc,项目名称:bluewatcher,代码行数:7,代码来源:License.java

示例10: getAuthority

import android.app.Activity; //导入方法依赖的package包/类
/**
 * get the authority of FileProvider.
 * @param activity the activity.
 * @return the authority
 */
protected String getAuthority(Activity activity){
    return activity.getPackageName() + ".fileprovider";
}
 
开发者ID:LightSun,项目名称:android-util2,代码行数:9,代码来源:ImageHelper.java


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