本文整理汇总了Java中android.os.StrictMode.ThreadPolicy方法的典型用法代码示例。如果您正苦于以下问题:Java StrictMode.ThreadPolicy方法的具体用法?Java StrictMode.ThreadPolicy怎么用?Java StrictMode.ThreadPolicy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.StrictMode
的用法示例。
在下文中一共展示了StrictMode.ThreadPolicy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.os.StrictMode; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//check is tablet or not
if(isTablet(getApplicationContext())){
setContentView(R.layout.activity_home);
}else{
setContentView(R.layout.activity_home1);
}
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
//get and set screen resolution
QuranConfig.getResolutionURLLink(this);
//init application views
init();
}
示例2: onCreate
import android.os.StrictMode; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(getClass().getSimpleName(), "Start MainActivity");
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Config.instance.init(this);
DeviceManager.instance.setContext(this);
WifiManager.instance.init(this);
BLEManager.instance.init(this);
try {
mServer = new WebService(this);
startService(new Intent(this, CloudPublisherService.class));
}catch (Exception e){
Log.e(getClass().getSimpleName(), e.toString());
}
}
示例3: getDownloadsDirectory
import android.os.StrictMode; //导入方法依赖的package包/类
/**
* @return the public downloads directory.
*/
@SuppressWarnings("unused")
@CalledByNative
private static String getDownloadsDirectory(Context appContext) {
// Temporarily allowing disk access while fixing. TODO: http://crbug.com/508615
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
String downloadsPath;
try {
long time = SystemClock.elapsedRealtime();
downloadsPath = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS).getPath();
RecordHistogram.recordTimesHistogram("Android.StrictMode.DownloadsDir",
SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
return downloadsPath;
}
示例4: onCreate
import android.os.StrictMode; //导入方法依赖的package包/类
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
setContentView(R.layout.socket_connection_build);
ed_host = (EditText) findViewById(R.id.ed_host);
ed_port = (EditText) findViewById(R.id.ed_port);
btn_connect = (Button) findViewById(R.id.btn_connect);
/* Fetch earlier defined host ip and port numbers and write them as default
* (to avoid retyping this, typically standard, info) */
SharedPreferences mSharedPreferences = getSharedPreferences("list",MODE_PRIVATE);
String oldHost = mSharedPreferences.getString("host", null);
if (oldHost != null)
ed_host.setText(oldHost);
int oldPortCommunicator = mSharedPreferences.getInt("port",0);
if (oldPortCommunicator != 0)
ed_port.setText(Integer.toString(oldPortCommunicator));
}
示例5: getUriForItem
import android.os.StrictMode; //导入方法依赖的package包/类
/**
* Returns a URI that points at the file.
* @param file File to get a URI for.
* @return URI that points at that file, either as a content:// URI or a file:// URI.
*/
public static Uri getUriForItem(File file) {
Uri uri = null;
// #getContentUriFromFile causes a disk read when it calls into FileProvider#getUriForFile.
// Obtaining a content URI is on the critical path for creating a share intent after the
// user taps on the share button, so even if we were to run this method on a background
// thread we would have to wait. As it depends on user-selected items, we cannot
// know/preload which URIs we need until the user presses share.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
// Try to obtain a content:// URI, which is preferred to a file:// URI so that
// receiving apps don't attempt to determine the file's mime type (which often fails).
uri = ContentUriUtils.getContentUriFromFile(ContextUtils.getApplicationContext(), file);
} catch (IllegalArgumentException e) {
Log.e(TAG, "Could not create content uri: " + e);
}
StrictMode.setThreadPolicy(oldPolicy);
if (uri == null) uri = Uri.fromFile(file);
return uri;
}
示例6: startChromeBrowserProcessesSync
import android.os.StrictMode; //导入方法依赖的package包/类
private void startChromeBrowserProcessesSync() throws ProcessInitException {
try {
TraceEvent.begin("ChromeBrowserInitializer.startChromeBrowserProcessesSync");
ThreadUtils.assertOnUiThread();
mApplication.initCommandLine();
LibraryLoader libraryLoader = LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER);
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
libraryLoader.ensureInitialized();
StrictMode.setThreadPolicy(oldPolicy);
libraryLoader.asyncPrefetchLibrariesToMemory();
BrowserStartupController.get(mApplication, LibraryProcessType.PROCESS_BROWSER)
.startBrowserProcessesSync(false);
GoogleServicesManager.get(mApplication);
} finally {
TraceEvent.end("ChromeBrowserInitializer.startChromeBrowserProcessesSync");
}
}
示例7: startActivityIfNeeded
import android.os.StrictMode; //导入方法依赖的package包/类
@Override
public boolean startActivityIfNeeded(Intent intent, boolean proxy) {
boolean activityWasLaunched;
// Only touches disk on Kitkat. See http://crbug.com/617725 for more context.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.allowThreadDiskReads();
try {
forcePdfViewerAsIntentHandlerIfNeeded(mApplicationContext, intent);
if (proxy) {
dispatchAuthenticatedIntent(intent);
activityWasLaunched = true;
} else {
Context context = getAvailableContext();
if (context instanceof Activity) {
activityWasLaunched = ((Activity) context).startActivityIfNeeded(intent, -1);
} else {
activityWasLaunched = false;
}
}
if (activityWasLaunched) recordExternalNavigationDispatched(intent);
return activityWasLaunched;
} catch (RuntimeException e) {
IntentUtils.logTransactionTooLargeOrRethrow(e, intent);
return false;
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
}
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:29,代码来源:ExternalNavigationDelegateImpl.java
示例8: initializeLocale
import android.os.StrictMode; //导入方法依赖的package包/类
/**
* Is only required by locale aware activities, AND Application. In most cases you should be
* using LocaleAwareAppCompatActivity or friends.
* @param context
*/
public static void initializeLocale(Context context) {
final LocaleManager localeManager = LocaleManager.getInstance();
final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads();
StrictMode.allowThreadDiskWrites();
try {
localeManager.getAndApplyPersistedLocale(context);
} finally {
StrictMode.setThreadPolicy(savedPolicy);
}
}
示例9: cayenneService
import android.os.StrictMode; //导入方法依赖的package包/类
/**
* Dagger DI provider method for {@link CayenneService}
*
* @param context
* android context used by {@link DefaultCayenneService} service internally
* @return Cayenne service implementation
*/
@Provides
@Singleton
public CayenneService cayenneService(Context context) {
// TODO: Cayenne temp ID functionality uses Localhost address,
// TODO: i.e. network activity in terms of Android.
// TODO: Without explicit permission here Cayenne will permanently fail to create new objects.
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
// This installs "assets:" url schema handler, this may be not optimal solution.
UrlToAssetUtils.registerHandler(context.getAssets());
return new DefaultCayenneService(context);
}
示例10: onCreate
import android.os.StrictMode; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
prefs = getSharedPreferences("com.threebetasonematt.a420game", MODE_PRIVATE);
//get reference for username box
mEnterUsername = (EditText)findViewById(R.id.edittext_enter_username);
//handle play button
mPlayButton = (Button)findViewById(R.id.button_splash_play);
mPlayButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = mEnterUsername.getText().toString();
if(username.equals("") || username.equals(null)){
//display error if the username is bad
Toast.makeText(InitialActivity.this, R.string.blank_username_error, Toast.LENGTH_SHORT).show();
}
else{
//open next activity
Intent intent = new Intent(InitialActivity.this, StartGameActivity.class);
intent.putExtra(constants.KEY_USERNAME, username);
SocketHandler.username = username;
startActivity(intent);
}
}
});
}
示例11: Register
import android.os.StrictMode; //导入方法依赖的package包/类
public Register(Activity cont, PreferencesShared pref) throws IOException {
this.context = cont;
preferencesShared = pref;
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
con = (HttpURLConnection) (new URL(this.context.getString(R.string.api_url)+this.context.getString(R.string.register_url))).openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type","application/json");
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(true);
con.connect();
}
示例12: createVrShell
import android.os.StrictMode; //导入方法依赖的package包/类
private boolean createVrShell() {
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
StrictMode.allowThreadDiskWrites();
try {
Constructor<?> vrShellConstructor = mVrShellClass.getConstructor(Activity.class);
mVrShell = (VrShell) vrShellConstructor.newInstance(mActivity);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException e) {
Log.e(TAG, "Unable to instantiate VrShell", e);
return false;
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
return true;
}
示例13: onCreate
import android.os.StrictMode; //导入方法依赖的package包/类
/**
* Figure out how to route the Intent. Because this is on the critical path to startup, please
* avoid making the pathway any more complicated than it already is. Make sure that anything
* you add _absolutely has_ to be here.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
// Third-party code adds disk access to Activity.onCreate. http://crbug.com/619824
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
TraceEvent.begin("ChromeLauncherActivity");
TraceEvent.begin("ChromeLauncherActivity.onCreate");
try {
super.onCreate(savedInstanceState);
doOnCreate(savedInstanceState);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
TraceEvent.end("ChromeLauncherActivity.onCreate");
}
}
示例14: restoreTab
import android.os.StrictMode; //导入方法依赖的package包/类
private void restoreTab(TabRestoreDetails tabToRestore, boolean setAsActive) {
// As we do this in startup, and restoring the active tab's state is critical, we permit
// this read in the event that the prefetch task is not available. Either:
// 1. The user just upgraded, has not yet set the new active tab id pref yet. Or
// 2. restoreTab is used to preempt async queue and restore immediately on the UI thread.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
long time = SystemClock.uptimeMillis();
TabState state;
int restoredTabId = mPreferences.getInt(PREF_ACTIVE_TAB_ID, Tab.INVALID_TAB_ID);
if (restoredTabId == tabToRestore.id && mPrefetchActiveTabTask != null) {
long timeWaitingForPrefetch = SystemClock.uptimeMillis();
state = mPrefetchActiveTabTask.get();
logExecutionTime("RestoreTabPrefetchTime", timeWaitingForPrefetch);
} else {
// Necessary to do on the UI thread as a last resort.
state = TabState.restoreTabState(getStateDirectory(), tabToRestore.id);
}
logExecutionTime("RestoreTabTime", time);
restoreTab(tabToRestore, state, setAsActive);
} catch (Exception e) {
// Catch generic exception to prevent a corrupted state from crashing the app
// at startup.
Log.d(TAG, "loadTabs exception: " + e.toString(), e);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
}
示例15: getThreadPolicy
import android.os.StrictMode; //导入方法依赖的package包/类
@Nullable
StrictMode.ThreadPolicy getThreadPolicy();