本文整理了Java中android.app.Activity.getPackageName()
方法的一些代码示例,展示了Activity.getPackageName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Activity.getPackageName()
方法的具体详情如下:
包路径:android.app.Activity
类名称:Activity
方法名:getPackageName
暂无
代码示例来源:origin: stackoverflow.com
public static void startInstalledAppDetailsActivity(final Activity context) {
if (context == null) {
return;
}
final Intent i = new Intent();
i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
i.addCategory(Intent.CATEGORY_DEFAULT);
i.setData(Uri.parse("package:" + context.getPackageName()));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
context.startActivity(i);
}
代码示例来源:origin: jiangqqlmj/FastDev4Android
public static String getPackageName(Activity activity) {
String packageName = null;
try {
packageName = String.valueOf(activity.getPackageManager()
.getPackageInfo(activity.getPackageName(), 0).packageName);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return packageName;
}
代码示例来源:origin: jiangqqlmj/FastDev4Android
public static String getVersionName(Activity activity) {
String version = null;
try {
version = String.valueOf(activity.getPackageManager()
.getPackageInfo(activity.getPackageName(), 0).versionName);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return version;
}
代码示例来源:origin: wangdan/AisenWeiBo
public static void launch(Activity from, String screenName) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("org.aisen.weibo.sina.userinfo://@%s", screenName)));
intent.putExtra(Browser.EXTRA_APPLICATION_ID, from.getPackageName());
from.startActivity(intent);
}
代码示例来源:origin: jokermonn/permissions4m
@Override
public Intent settingIntent() throws Exception {
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(PACK_TAG, context.getPackageName());
ComponentName comp;
comp = new ComponentName(PKG, MANAGER_OUT_CLS);
// do not work!!
// comp = new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission" + ".PermissionAppAllPermissionActivity");
intent.setComponent(comp);
return intent;
}
}
代码示例来源:origin: jiajunhui/PlayerBase
public static boolean checkPermission(Activity activity){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& !Settings.canDrawOverlays(activity)) {
Toast.makeText(activity, "当前无权限,请授权", Toast.LENGTH_SHORT).show();
activity.startActivityForResult(
new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + activity.getPackageName())), 0);
return false;
}
return true;
}
代码示例来源:origin: jokermonn/permissions4m
@Override
public Intent settingIntent() {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
intent.setData(uri);
return intent;
}
}
代码示例来源:origin: aa112901/remusic
/**
* 打开应用设置界面
*
* @param requestCode 请求码
*
* @return
*/
private boolean openApplicationSettings(int requestCode) {
try {
Intent intent =
new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + mActivity.getPackageName()));
intent.addCategory(Intent.CATEGORY_DEFAULT);
// Android L 之后Activity的启动模式发生了一些变化
// 如果用了下面的 Intent.FLAG_ACTIVITY_NEW_TASK ,并且是 startActivityForResult
// 那么会在打开新的activity的时候就会立即回调 onActivityResult
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mActivity.startActivityForResult(intent, requestCode);
return true;
} catch (Throwable e) {
Log.e(TAG, "", e);
}
return false;
}
代码示例来源:origin: jokermonn/permissions4m
@Override
public Intent settingIntent() throws Exception {
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(PACK_TAG, activity.getPackageName());
ComponentName comp = new ComponentName(PKG, getCls());
intent.setComponent(comp);
return intent;
}
代码示例来源:origin: jokermonn/permissions4m
@Override
public Intent settingIntent() throws ActivityNotFoundException {
Intent intent = new Intent();
String miuiInfo = getSystemProperty();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (miuiInfo.contains("7") || miuiInfo.contains("6")) {
intent = new Intent("miui.intent.action.APP_PERM_EDITOR");
intent.setClassName(PKG, MIUI7_MANAGER_OUT_CLS);
intent.putExtra("extra_pkgname", context.getPackageName());
} else {
// miui 8
intent.putExtra(PACK_TAG, context.getPackageName());
ComponentName comp = new ComponentName(PKG, MIUI8_MANAGER_OUT_CLS);
intent.setComponent(comp);
}
return intent;
}
}
代码示例来源:origin: jokermonn/permissions4m
@Override
public Intent settingIntent() throws Exception {
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(PACK_TAG, context.getPackageName());
ComponentName comp = new ComponentName(PKG, MAIN_CLS);
// starting Intent { flg=0x10000000 cmp=com.iqoo.secure/.safeguard.PurviewTabActivity (has
// extras) } from ProcessRecord
// ComponentName comp = new ComponentName(PKG, "com.iqoo.secure.safeguard.PurviewTabActivity");
// can enter, but blank
// try {
// PackageInfo pi = context.getPackageManager().getPackageInfo(PKG,
// PackageManager.GET_ACTIVITIES);
// for (ActivityInfo activityInfo : pi.activities) {
// Log.e("TAG", "settingIntent: " + activityInfo.name);
// if (activityInfo.name.contains(IN_CLS)) {
// comp = new ComponentName(PKG, "com.iqoo.secure.safeguard
// .SoftPermissionDetailActivity");
// }
// }
// } catch (PackageManager.NameNotFoundException e) {
// e.printStackTrace();
// }
intent.setComponent(comp);
return intent;
}
}
代码示例来源:origin: commonsguy/cw-omnibus
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int res=
getActivity().getResources()
.getIdentifier(getArguments().getString("resource"),
"xml",
getActivity().getPackageName());
addPreferencesFromResource(res);
}
}
代码示例来源:origin: commonsguy/cw-omnibus
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int res=
getActivity().getResources()
.getIdentifier(getArguments().getString("resource"),
"xml",
getActivity().getPackageName());
addPreferencesFromResource(res);
}
}
代码示例来源:origin: jdamcd/android-crop
@Override
public void setUp() throws Exception {
super.setUp();
activity = mock(Activity.class);
when(activity.getPackageName()).thenReturn("com.example");
builder = Crop.of(Uri.parse("image:input"), Uri.parse("image:output"));
}
代码示例来源:origin: seven332/EhViewer
PackageInfo pi = pm.getPackageInfo(mActivity.getPackageName(), PackageManager.GET_ACTIVITIES);
int currentVersionCode = pi.versionCode;
versionCode = jo.getInt("version_code");
代码示例来源:origin: square/picasso
@Override public void launch(Activity activity) {
RemoteViews remoteViews =
new RemoteViews(activity.getPackageName(), R.layout.notification_view);
Intent intent = new Intent(activity, SampleGridViewActivity.class);
Notification notification =
new NotificationCompat.Builder(activity, CHANNEL_ID)
.setSmallIcon(R.drawable.icon)
.setContentIntent(PendingIntent.getActivity(activity, -1, intent, 0))
.setContent(remoteViews)
.setAutoCancel(true)
.setChannelId(CHANNEL_ID)
.build();
NotificationManager notificationManager =
(NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel =
new NotificationChannel(CHANNEL_ID, "Picasso Notification Channel",
NotificationManager.IMPORTANCE_DEFAULT);
notificationManager.createNotificationChannel(channel);
}
notificationManager.notify(NOTIFICATION_ID, notification);
// Now load an image for this notification.
PicassoProvider.get() //
.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);
}
};
代码示例来源:origin: facebook/facebook-android-sdk
if (callingApplication != null) {
callingApplicationPackage = callingApplication.getPackageName();
if (callingApplicationPackage.equals(activity.getPackageName())) {
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldRetrievePackageNameFromTheManifest() throws Exception {
assertThat(Robolectric.setupActivity(Activity.class).getPackageName())
.isEqualTo(ApplicationProvider.getApplicationContext().getPackageName());
}
代码示例来源:origin: facebook/facebook-android-sdk
if (callingApplication != null) {
String callingApplicationPackage = callingApplication.getPackageName();
if (callingApplicationPackage.equals(activity.getPackageName())) {
代码示例来源:origin: bluelinelabs/Conductor
private void addChild(final int index) {
@IdRes final int frameId = getResources().getIdentifier("child_content_" + (index + 1), "id", getActivity().getPackageName());
final ViewGroup container = (ViewGroup)getView().findViewById(frameId);
final Router childRouter = getChildRouter(container).setPopsLastView(true);
内容来源于网络,如有侵权,请联系作者删除!