我将TEXT文件附加到电子邮件中,代码如下:
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",
"abc@gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Report");
emailIntent.putExtra(Intent.EXTRA_TEXT, prepareBodyMail());
File root = Environment.getExternalStorageDirectory();
File file = new File(root, "/MyFolder/report.txt");
Uri uri = Uri.fromFile(file);
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(emailIntent, "Pick an Email provider"));
Run Code Online (Sandbox Code Playgroud)
此代码与Gmail,电子邮件和其他应用程序完美配合
但这并不是谷歌附带INBOX应用程序的文件
只有身体和主体没有任何依恋
任何人都能帮助我在代码中缺少什么吗?
我一直在尝试在 Android Jetpack Compose 的动态列表中显示AlertDialogfrom 。onClickCard
我在执行此操作时收到编译时错误@Composable 调用只能从 @Composable 函数的上下文中发生。
下面是我的代码片段:
@Preview(showBackground = true)
@Composable
fun prepareCard(card: Card) {
MyApplicationTheme() {
androidx.compose.material.Card() {
Column(Modifier.clickable {
Log.d("TAG", "clicked : " + card.name)
val showDialog = mutableStateOf(true)
if (showDialog.value) {
alert(card)
}
...
}
}
}
Run Code Online (Sandbox Code Playgroud)
我已经制作了alert()从上面的代码调用的可组合函数
@Composable
fun alert(card : Card) {
AlertDialog(
title = {
Text("")
},
text = {
Text(text = card.name)
}, onDismissRequest = {
},
confirmButton = {},
dismissButton = …Run Code Online (Sandbox Code Playgroud) android android-alertdialog kotlin android-jetpack-compose android-compose-dialog
我需要ImageView使用平滑的动画从屏幕的左侧到右侧制作幻灯片(我想ImageView在转换过程中看到它)我尝试使用以下代码:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
camion.animate()
.translationX(width)
.setDuration(2000)
.setInterpolator(new LinearInterpolator())
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
//camion.setVisibility(View.GONE);
}
});
Run Code Online (Sandbox Code Playgroud)
在ImageView移动,但在动画laggy,而不是光滑如我想.我在代码上做错了什么?
我在stackoverflow中看到了类似的问题,但他们没有给出我的问题的明确答案.在阅读完整的问题之前,请勿将其标记为重复.我看到了这个链接,这也是这个.感谢您花时间阅读本文.
我在源代码下面给出了三个问题,请仔细看看.
我会简单的.我试图在Recycler Adapter中使用两个 ViewHolder,我将在ViewPager中使用TabLayout.两个View Holder都有不同的 Xml和不同的元素(即textview,imageview等......)但是它内部有几个混乱.
我实现了我的RecyclerView适配器类,如下所示
public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public class MainViewHolder extends RecyclerView.ViewHolder {
public MainViewHolder(View v) {
super(v);
}
class ViewHolder0 extends MainViewHolder {
...
}
class ViewHolder2 extends MainViewHolder {
...
}
@Override
public int getItemViewType(int position) {
/**** I don't know where and when this method will be called and what will be the value present in the variable …Run Code Online (Sandbox Code Playgroud) 任何人都可以明确功能之间的关系 CoroutineScope()和coroutineScope()?
当我尝试检查源代码时,我发现它们都是CoroutineScope.kt. 此外,coroutineScope()是suspend函数而另一个是normal函数
以下是我可以找到的文档:
/**
* Creates a [CoroutineScope] that wraps the given coroutine [context].
*
* If the given [context] does not contain a [Job] element, then a default `Job()` is created.
* This way, cancellation or failure or any child coroutine in this scope cancels all the other children,
* just like inside [coroutineScope] block.
*/
@Suppress("FunctionName")
public fun CoroutineScope(context: CoroutineContext): CoroutineScope =
ContextScope(if (context[Job] != …Run Code Online (Sandbox Code Playgroud) Google为1.距离矩阵和2.方向服务提供API
我试图搜索1和2之间的差异
我的任务是"当用户 使用某个路径从Source S移动到Destination D时.我们需要显示用户在Google Map上遍历的实际路径 "
什么是实现它的最佳方法?
使用1.距离矩阵API或2.方向服务
我正在与蓝牙设备进行蓝牙套接字连接,并希望从设备读取字节.
我已正确建立连接:
try {
Method m = mmDevice.getClass().getMethod("createRfcommSocket", new Class[] { int.class });
temp = (BluetoothSocket) m.invoke(mmDevice, 1);
} catch (Exception e) {
}
Run Code Online (Sandbox Code Playgroud)
我正在从蓝牙设备正确读取字节.
我得到了例外:
java.io.IOException:读取失败,socket可能关闭或超时,读取ret:-1
因此,连接断开,我的设备和蓝牙设备之间的通信也结束了.
这个问题特别在Android 5.0.1 Lollipop上出现
任何人都有解决方法吗?
我有一个外部变量和一个数组声明的问题.如何使用不在可声明文件中的全局变量声明数组.
file1.cpp
const int size = 10;
Run Code Online (Sandbox Code Playgroud)
mainfile.cpp
extern const int size;
void main()
{
int mas[size];
}
Run Code Online (Sandbox Code Playgroud)
int mas[size];
Run Code Online (Sandbox Code Playgroud)
这条线有一个问题.请猜猜想?
我有两个应用程序,一个作为主应用程序,另一个作为服务.在服务应用清单文件中,我配置了如下服务:
<service android:name=".services.FirstService">
<intent-filter>
<action android:name="ch.service.action.FIRST_SERVICE"/>
</intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)
在主应用程序中,我启动了一项服务:
Intent intent = new Intent("ch.service.action.FIRST_SERVICE");
startService(intent);
Run Code Online (Sandbox Code Playgroud)
在这里,我必须复制"ch.service.action.FIRST_SERVICE".我怎么能避免这个?我如何分享一些常见的常量,例如在服务应用中定义一个,并且可以在主应用中检索?
任何答案都表示赞赏.
我function通过单击按钮来调用(非暂停)。我想function使用async协程运行一个循环并返回最后的计算值。
我的代码:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
btnCount.setOnClickListener {
var result = GlobalScope.async { dummyFoo() }
runBlocking {
Toast.makeText(this@MainActivity, result.await().toString(), Toast.LENGTH_LONG).show()
}
}
}
private fun dummyFoo() : Int {
var result : Int = 0
val waitFor = CoroutineScope(Dispatchers.IO).async {
for (i in 1..20000) {
result++
}
return@async result
}
return result
}
Run Code Online (Sandbox Code Playgroud)
输出 :
我得到了0分Toast。
我要20000元Toast
如何让我的代码等待循环完成并20000输出结果?
android ×9
kotlin ×3
adapter ×1
arrays ×1
async-await ×1
bluetooth ×1
c++ ×1
const ×1
extern ×1
google-inbox ×1
google-maps ×1
java ×1
suspend ×1