我已将我的应用程序构建为已签名的SDK.我希望beta测试人员能够在他们的设备上安装这个,而无需安装和使用android sdk工具(我意识到apk可以使用命令行工具安装,但是更喜欢没有必要).
我尝试手动安装它,但它失败了.我有一个安卓平板电脑,我正在测试.我将apk复制到我设备的SD卡上,然后点击它.这提供了使用App Manager安装它的选项.不幸的是,安装失败并显示消息"Application not installed".
有没有办法手动安装apk,而不使用命令行工具?
我的应用程序允许用户创建和修改文件.我希望他们能够将文件作为电子邮件附件发送.所以,我需要先创建并写入一个临时文件,然后将其附加到电子邮件中.然后我想在电子邮件程序完成时删除临时文件.不幸的是,一旦用户点击"发送",gmail应用就会响应结果代码; 如果我在收到结果代码后立即删除该文件,则不会发送任何附件.
它可能出现其他问题并且附件不是由于其他原因而发送的,但我非常确定我的评估是正确的,因为如果我注释掉这个mEmailTmpFile.delete()调用,下面的代码就能正常工作.如果我做Thread.sleep(4000)之前非常不受欢迎的事情,它也可以正常工作mEmailTmpFile.delete().
无论如何,当电子邮件发送完成时,是否会收到通知?或者关于我应该如何解决这个问题的任何其他建议?
//send an email...
File externalStorage = Environment.getExternalStorageDirectory();
String sdcardPath = externalStorage.getAbsolutePath();
mEmailTmpFile = new File(sdcardPath + "/" + name );
//do some other to ensure unqiueness and then write to the file...
//all done writing, send email
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("application/zip");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, name);
sendIntent.putExtra(Intent.EXTRA_TEXT, "File attached.");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+ mEmailTmpFile.getPath()));
startActivityForResult(Intent.createChooser(sendIntent, "Email"), REQUESTCODE_EMAIL);
public synchronized void onActivityResult(int reqCode, int resultCode, Intent data)
{
if (reqCode == REQUESTCODE_EMAIL)
{
mEmailTmpFile.delete(); …Run Code Online (Sandbox Code Playgroud) 我在垂直LinearLayout中有一系列视图.滚动到时,每个视图都会生成并绘制一个位图.出于性能原因,每次调用onDraw()时我宁愿不生成Bitmap,但出于内存原因,我无法保留对Bitmaps的硬引用.我可以就我应该采取的策略提出建议.
我已经尝试过明显的路径:生成Bitmap,然后用SoftReference包装它.这失败有两个原因.1.参考文献收集得比我预期的要热烈得多.我还是得到了OOM!这是令人震惊的,因为没有Bitmap特别大,所以单个视图不应该导致OOM,让我假设OOM发生,因为违规的SoftReference没有被释放的机会.此外,当我的应用程序的分配堆大小为6mb时(根据DDMS视图),OOM会发生,我希望它在抛出OOM之前增长到16mb.
有什么建议?
我有一个View,它绘制一个矩形,里面有一行文字.视图使用中断文本以确保没有文本扩展到矩形之外; 它会忽略任何文本.这适用于某些角色,但通常由'l'和'f'构成的字符串在矩形之外延伸.所以,我需要在这里进行健全性检查:我的下面的代码中是否存在明显的缺陷,或者Paint.breakText(...)是否可能不准确?
public void onDraw(Canvas canvas)
{
int MARGIN = 1;
int BORDER_WIDTH = 1;
Paint p = new Paint();
p.setAntiAlias(true);
p.setTextSize(12);
p.setTypeface(Typeface.create(Typeface.SERIF, Typeface.NORMAL));
RectF rect = getRect();
float maxWidth = rect.width() - MARGIN - BORDER_WIDTH * 2;
String str = getText();
char[] chars = str.toCharArray();
int nextPos = p.breakText(chars, 0, chars.length, maxWidth, null);
str = str.substring(0, nextPos);
float textX = MARGIN + BORDER_WIDTH;
float textY = (float) (Math.abs(p.getFontMetrics().ascent) + BORDER_WIDTH + MARGIN);
canvas.drawText(str, textX, textY, p);
p.setStrokeWidth(BORDER_WIDTH);
p.setStyle(Style.STROKE);
canvas.drawRect(rect, …Run Code Online (Sandbox Code Playgroud) 我的GridView包含固定宽度的列,具有固定的水平间距.如果没有足够的列horziontally占满整个屏幕,我想我的GridView的宽度来包装其内容,并在屏幕上垂直居中.
但是,无论我使用多少列,GridView的宽度都会增加以填充屏幕.附图显示了这一点,绿色GridView水平填充屏幕,尽管只有3列,其宽度设置为"wrap_content".
public class Temp extends Activity
{
private GridView grid;
private int columnWidth = 80;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
View view = getLayoutInflater().inflate(R.layout.gridview, null);
grid = (GridView) view.findViewById(R.id.grid);
grid.setColumnWidth(columnWidth);
grid.setAdapter(new GridAdapter());
setContentView(view);
}
class GridAdapter extends BaseAdapter
{
public GridAdapter()
{
}
public int getCount()
{
return 3;
}
public Object getItem(int position)
{
return null;
}
public long getItemId(int position)
{
return position;
}
public View getView (int position, View convertView, ViewGroup parent)
{
View …Run Code Online (Sandbox Code Playgroud) 除非我调用Connection.commit(),否则数据库游标在查询后保持打开状态。我相信这种行为正在导致我的应用程序泄漏游标并遇到与游标使用相关的数据库错误。
似乎该commit()呼叫应该是不必要的...是这种现象吗?有什么方法可以配置JDBC连接池,以便在关闭资源时可靠地释放游标,而无需调用commit?
我正在使用此查询来查找打开的游标:
select * from v$open_cursor where CURSOR_TYPE = 'OPEN'
如果我commit()在关闭statement和之后致电ResultSet,则在sleep()
try (Connection con = pooledDataSource.getConnection()) {
try (PreparedStatement statement = con.prepareStatement("select 1 from dual a");
ResultSet rs = statement.executeQuery()) {
}
con.commit();
}
Thread.sleep(20000);
Run Code Online (Sandbox Code Playgroud)
如果在close statement和之前调用commit ResultSet,则select 1 from b在sleep()期间查询打开的游标时会找到sql 。
try (Connection con = pooledDataSource.getConnection();
PreparedStatement statement = con.prepareStatement("select 1 from dual b");
ResultSet rs = statement.executeQuery()) {{
con.commit();
}}
Thread.sleep(20000);
Run Code Online (Sandbox Code Playgroud)
这里也是一样。如果我不打电话, …
我的应用程序包括一个发送功能,它显示了用于发送文档的已安装程序的列表.它通过以下方式实现:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("application/zip");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+ docPath));
startActivity(Intent.createChooser(sendIntent, "Email"));
Run Code Online (Sandbox Code Playgroud)
Gmail和Dropbox等应用程序会显示在列表中,但Google Docs则不会.在竞争对手使用相同文档类型的应用中,Google Docs确实显示为意图.我是否必须使用其他方法或意图类型才能显示Google文档?
我想创建一个Android虚拟设备,我可以用它来测试写入外部SD卡的最新问题.我希望在AVD文件系统上的"/ storage/extSdCard/DCIM /"位置找到外部SD卡.有关如何实现这一目标的任何建议?
使用邮递员,我可以得到用户的列表与GET请求: http://localhost:8080/users。
但是,当我向同一地址发送邮寄请求时,出现403错误。
@RestController
public class UserResource {
@Autowired
private UserRepository userRepository;
@GetMapping("/users")
public List<User> retrievaAllUsers() {
return userRepository.findAll();
}
@PostMapping("/users")
public ResponseEntity<Object> createUser(@RequestBody User user) {
User savedUser = userRepository.save(user);
URI location = ServletUriComponentsBuilder.fromCurrentRequest()
.path("/{id}")
.buildAndExpand(savedUser.getId())
.toUri();
return ResponseEntity.created(location).build();
}
}
@EnableWebSecurity
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
/*@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(userDetailsService)
.passwordEncoder(new BCryptPasswordEncoder());
}*/
/*@Override
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic().and().authorizeRequests() …Run Code Online (Sandbox Code Playgroud) 我想在我的ActionBar中显示一个微调器,使用ActionBar.NAVIGATION_MODE_LIST,但我希望它基于一些应用程序上下文隐藏/显示.我发现我可以将它从ActionBar中移除getActionBar().setNavigationMode(-1),但我不知道这是不是一个好主意.
关于这是否安全或是否有更安全的替代方案的任何反馈?