當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。