List of usage examples for android.app Activity getApplication
public final Application getApplication()
From source file:com.yalin.fidoclient.api.UAFClientApi.java
public static void doCheckPolicy(Activity activity, int requestCode, String responseMessage) { if (activity == null || TextUtils.isEmpty(responseMessage)) { throw new IllegalArgumentException(); }/*from ww w .j a v a2 s. co m*/ Intent intent = UAFIntent.getCheckPolicyIntent(new UAFMessage(responseMessage).toJson(), activity.getApplication().getPackageName()); activity.startActivityForResult(intent, requestCode); }
From source file:com.dmitrymalkovich.android.githubanalytics.Utils.java
public static void openFeedback(Activity activity) { try {//from w w w. j a v a 2 s . c o m throw new IOException(); } catch (IOException e) { ApplicationErrorReport report = new ApplicationErrorReport(); report.packageName = report.processName = activity.getApplication().getPackageName(); report.time = System.currentTimeMillis(); report.type = ApplicationErrorReport.TYPE_CRASH; report.systemApp = false; ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo(); crash.exceptionClassName = e.getClass().getSimpleName(); crash.exceptionMessage = e.getMessage(); StringWriter writer = new StringWriter(); PrintWriter printer = new PrintWriter(writer); e.printStackTrace(printer); crash.stackTrace = writer.toString(); StackTraceElement stack = e.getStackTrace()[0]; crash.throwClassName = stack.getClassName(); crash.throwFileName = stack.getFileName(); crash.throwLineNumber = stack.getLineNumber(); crash.throwMethodName = stack.getMethodName(); report.crashInfo = crash; Intent intent = new Intent(Intent.ACTION_APP_ERROR); intent.putExtra(Intent.EXTRA_BUG_REPORT, report); activity.startActivity(intent); } }
From source file:com.facebook.unity.FB.java
private static void ActivateApp(String appId) { if (!activateAppCalled.compareAndSet(false, true)) { Log.w(TAG, "Activite app only needs to be called once"); return;//ww w . ja v a 2 s . c om } final Activity unityActivity = getUnityActivity(); if (appId != null) { AppEventsLogger.activateApp(unityActivity.getApplication(), appId); } else { AppEventsLogger.activateApp(unityActivity.getApplication()); } // We already have a running activity so we need to call create activity to ensure the // logging is correct new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { // These calls should be run on the ui thread. ActivityLifecycleTracker.onActivityCreated(unityActivity); ActivityLifecycleTracker.onActivityResumed(unityActivity); } }); }
From source file:org.awesomeapp.messenger.ui.ContactsListFragment.java
private static void deleteContact(Activity activity, long itemId, String address, long providerId, long accountId) { try {/*from www .j a v a2 s.c om*/ IImConnection mConn; ImApp app = ((ImApp) activity.getApplication()); mConn = app.getConnection(providerId, accountId); //first leave, delete an existing chat session IChatSessionManager sessionMgr = mConn.getChatSessionManager(); if (sessionMgr != null) { IChatSession session = sessionMgr.getChatSession(Address.stripResource(address)); } //then delete the contact from our list IContactListManager manager = mConn.getContactListManager(); int res = manager.removeContact(address); if (res != ImErrorInfo.NO_ERROR) { //mHandler.showAlert(R.string.error, // ErrorResUtils.getErrorRes(getResources(), res, address)); } } catch (RemoteException re) { } }
From source file:org.braiden.fpm2.PasswordItemListActivity.java
public static void launchItem(Activity activity, long id) { PasswordItem item = ((FpmApplication) activity.getApplication()).getPasswordItemById(id); if (item != null) { try {/*from w w w . j av a 2 s . com*/ boolean copyPassword = PreferenceManager.getDefaultSharedPreferences(activity) .getBoolean(FpmApplication.PREF_COPY_PASSWORD, false); if (copyPassword) { copyItemProperty(activity, id, FpmCrypt.PROPERTY_PASSWORD); } String uriString = item.getUrl(); if (LAUNCHER_WEB.equalsIgnoreCase(item.getLauncher()) && uriString.indexOf("://") < 0) { uriString = "http://" + uriString; } Uri uri = Uri.parse(uriString); Intent intent = new Intent(Intent.ACTION_VIEW, uri); activity.startActivity(intent); } catch (Exception e) { Log.i(TAG, "Cannot launch item (id=" + id + ").", e); } } }
From source file:org.braiden.fpm2.PasswordItemListActivity.java
public static void copyItemProperty(Activity activity, long id, String property) { FpmApplication app = (FpmApplication) activity.getApplication(); PasswordItem item = app.getPasswordItemById(id); if (item != null) { try {/* www . j ava 2 s. com*/ String value = (String) PropertyUtils.getProperty(item, property); if (FpmCrypt.PROPERTY_PASSWORD.equals(property)) { value = app.decrypt(value); } ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(CLIPBOARD_SERVICE); clipboard.setText(value); } catch (Exception e) { Log.w(TAG, "Failed to access property \"" + property + "\" of item id " + id + ".", e); } } }
From source file:Main.java
public static boolean isExistShortcut(Activity context, String authorities) { boolean isInstallShortcut = false; final ContentResolver cr = context.getContentResolver(); /*/*from w w w.j a va 2 s . c o m*/ * if (android.os.Build.VERSION.SDK_INT < 8) { AUTHORITIES = * "com.android.launcher.settings"; } else { AUTHORITIES = * "com.android.launcher2.settings"; } */ final Uri CONTENT_URI = Uri.parse("content://" + authorities + "/favorites?notify=true"); Cursor c = cr.query(CONTENT_URI, new String[] { "iconPackage" }, "iconPackage=?", new String[] { context.getApplication().getPackageName() }, null); if (c != null) { if (c.getCount() > 0) { isInstallShortcut = true; } c.close(); } return isInstallShortcut; }
From source file:com.auth0.lock.Lock.java
/** * Returns the Lock object from the Application object. * * @param activity that needs Lock instance * @return a Lock instance/*from www . j a v a 2s .c o m*/ */ public static Lock getLock(Activity activity) { Application application = activity.getApplication(); if (!(application instanceof LockProvider)) { throw new IllegalStateException("Android Application object must implement LockProvider interface"); } LockProvider provider = (LockProvider) application; return provider.getLock(); }
From source file:com.spoiledmilk.ibikecph.util.Util.java
public static void showLanguageDialog(final Activity activity) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(IbikeApplication.getString("choose_language")); builder.setItems(IbikePreferences.getLanguageNames(), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { ((IbikeApplication) activity.getApplication()).changeLanguage(Language.values()[item + 1]); ((iLanguageListener) activity).reloadStrings(); dialog.dismiss();/*from w w w . j ava 2 s . com*/ } }); builder.setPositiveButton(IbikeApplication.getString("Cancel"), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.show(); }
From source file:net.granoeste.scaffold.lifecyclecallbacks.LifecycleCallbacksSupportApplication.java
public static LifecycleCallbacksSupportApplication applicationOf(Context context) { if (context instanceof Activity) { Activity activity = (Activity) context; Application app = activity.getApplication(); if (app instanceof LifecycleCallbacksSupportApplication) { return (LifecycleCallbacksSupportApplication) app; }/* w w w . j a v a 2s. c o m*/ } if (context instanceof Service) { Service service = (Service) context; Application app = service.getApplication(); if (app instanceof LifecycleCallbacksSupportApplication) { return (LifecycleCallbacksSupportApplication) app; } } Context appContext = context.getApplicationContext(); if (appContext instanceof LifecycleCallbacksSupportApplication) { return (LifecycleCallbacksSupportApplication) appContext; } if (context instanceof ContextWrapper) { Context base = ((ContextWrapper) context).getBaseContext(); if (base != null) { if (base instanceof LifecycleCallbacksSupportApplication) { return (LifecycleCallbacksSupportApplication) base; } Context baseAppContext = base.getApplicationContext(); if (baseAppContext instanceof LifecycleCallbacksSupportApplication) { return (LifecycleCallbacksSupportApplication) baseAppContext; } } } return null; }