我正在使用Android studio 2.1.2.我已经检查过,大多数问题要么使用旧版本的Android工作室,要么使用一些不适用于我的情况的旧类.
从文件>新项目>我使用选项谷歌地图活动.我没有更改其中的任何默认代码.它的XML有一个片段.现在有没有办法通过Fragment将这个活动引入另一个Activity?基本上我正在构建一个应用程序,在屏幕的中间部分显示一个地图.这个中间部分,我希望将是一个片段.底部和顶部区域有一些组件供用户进行交互.
我并不是想让地图出现在一个新的活动中,而是保留在特定活动的中间部分.
或者我只是将新的UI组件添加到默认的Google地图活动中.
首先,我想到了创建一个Fragment(带有自己的.java文件,XML Layout),然后将地图代码放在那里并将其转移到我想要的Activity.完成这项工作的最佳方法是什么?我感谢任何帮助.
我正在尝试在 Android Studio 3.01 中使用电子邮件意图。如果我使用,即使同时安装了原生 Android 电子邮件客户端和 Gmail 电子邮件应用程序,ACTION_SENDTO我也会收到错误消息。No apps can perform this action如果我使用ACTION_SEND代替ACTION_SENDTO,则会显示一个屏幕,其中显示设备上的每个应用程序。
我的目标是直接调用默认电子邮件客户端,而不通过中间屏幕。我究竟做错了什么?
我正在使用的代码是:
public void sendEmail(View view) {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Log.i("Email sent!", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MapsActivityCurrentPlace.this,
"Email not installed.", Toast.LENGTH_SHORT).show();
}
}
Run Code Online (Sandbox Code Playgroud)
编辑
感谢答案,最终的工作代码如下所示:
public void sendEmail(View view) {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Message...");
try {
startActivity(emailIntent);
finish();
Log.i("Email sent!", …Run Code Online (Sandbox Code Playgroud) 我已经完成了 Android 应用程序的开发。我正在使用安卓工作室。当我通常在设备上以调试模式运行应用程序时,一切工作正常。连个例外也不例外。
但是,当我按照 Google 的指南创建应用程序的签名发行版本并将其安装到我的设备中时,应用程序在我启动后立即强制关闭。
我只是想不出一种方法来定位问题所在。我使用 Android studio IDE 中的“生成签名 apk”选项创建了发布版本。然后我将其复制到我的设备中并安装了该应用程序。然后当我跑步时,它立即停止工作。
我不知道我应该在这里提供什么更多信息,因为我无法推断这个问题的原因。
请帮忙。这些问题背后可能的原因是什么?我怎样才能找到它们?
编辑:
每次我解锁设备时,它都会显示对话框“MyApp 已停止工作”。logcat 里什么也没有。我不知道为什么会发生这种情况。我的应用程序使用这些权限:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.mypackagename.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.mypackagename.permission.C2D_MESSAGE" />
Run Code Online (Sandbox Code Playgroud) 我有一个名为 的片段MyRequestFragment,其中包含使用我的适配器类RecyclerView将数据绑定到RecyclerViewusing的片段onBindViewHolder()。
现在每个ViewHolder我都有一个按钮。并且每次单击按钮都会POST向服务器发出请求并更新值。我的问题是,如果出现成功响应,我需要隐藏特定ViewHolder.
实际问题是runOnUiThread()不接受onBindViewHolder()
runOnUiThread(new Runnable() {
public void run() {
}
});
Run Code Online (Sandbox Code Playgroud)
我如何在ViewHolder创建/绑定方法中调用它。
我的onBindViewHolder()完整代码如下供参考。
@Override
public void onBindViewHolder(MyServiceViewHolder holder, int position) {
final MyServiceBean myServiceBean = serviceList.get(position);
holder.service_name.setText(myServiceBean.getService_name());
holder.last_updated.setText("Job Updated Date : " +myServiceBean.getDate(myServiceBean.getUpdated_at()));
holder.created_date.setText("Job Created Date : " + myServiceBean.getDate(myServiceBean.getCreated_at()));
holder.status.setText(myServiceBean.getStatus());
holder.service_note.setText("Service Note : " + myServiceBean.getService_note());
if (myServiceBean.getService_note().toString().isEmpty())
holder.service_note.setVisibility(View.GONE);
switch (myServiceBean.getStatus().toString().toLowerCase()) {
case "completed":
holder.status.setBackgroundColor(Color.GREEN);
break; …Run Code Online (Sandbox Code Playgroud) 我从DB获取日期值作为长值.我将此转换为字符串以使用解析函数.以下是我的代码
Date date1 = new SimpleDateFormat("MM/dd/yyyy").parse(strDate1);
Run Code Online (Sandbox Code Playgroud)
但是当这个代码正在执行时,应用程序崩溃.如果执行该代码,它将成功执行
strDate1="12/30/2012".
Run Code Online (Sandbox Code Playgroud)
但我有这个值为" 12302012235 "(pzudo值).
我怎样才能做到这一点?
编辑:
我将日期值保存为DB为INTEGER.从DB我得到这个值并转换为string.this是实际的strDate1值
strDate1="1346524199000"
Run Code Online (Sandbox Code Playgroud) 我是android新手编程的新手,我在android studio中开发一个应用程序,我必须按下按钮输入数字,比如计算器,我的问题是在调试模式下测试手机上的应用程序,当我打开应用程序时通过发送此消息立即关闭:不幸的是"App"已停止,我正在使用LG-E425g(Android 4.1.2)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LytContenedor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<TextView android:id="@+id/LblNombre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ingrese"
android:textSize="25sp"
android:layout_weight="0.06"
android:layout_gravity="center_horizontal" />
<EditText
android:layout_width="345dp"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_gravity="center_horizontal"
android:inputType="text" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RytContenedor"
android:layout_width="563dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1"
android:layout_gravity="left">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="@+id/button"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:height="75dp"
android:width="75dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:padding="10dp"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:textSize="20sp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="@+id/button2"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/button"
android:layout_toEndOf="@+id/button"
android:width="75dp"
android:elegantTextHeight="false"
android:height="75dp"
android:textSize="20sp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:id="@+id/button3"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/button2"
android:layout_toEndOf="@+id/button2"
android:height="75dp"
android:width="75dp"
android:textSize="20sp" …Run Code Online (Sandbox Code Playgroud) 我是android新手...我希望在所有教程中都有一个底部动作栏的简单活动它提到有一种方法
android:uiOptions=”splitActionBarWhenNarrow”
Run Code Online (Sandbox Code Playgroud)
但即使我添加,它也无法在平板电脑或小型设备上运行
<meta-data android:name="android.support.UI_OPTIONS"
android:value="splitActionBarWhenNarrow" />
</activity>
Run Code Online (Sandbox Code Playgroud)
这是我的manifest.xml
<application
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:theme="@style/AppTheme"
>
<activity
android:name=".launchActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:uiOptions="splitActionBarWhenNarrow"
android:name=".MainActivity"
>
<meta-data android:name="android.support.UI_OPTIONS"
android:value="splitActionBarWhenNarrow" />
</activity>
<activity
android:name=".DisplayMessageActivity"
android:label="@string/title_activity_display_message" >
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
Run Code Online (Sandbox Code Playgroud)
构建文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "xxxxxxx"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建静态类ActivitySetup,该类用于为我的活动设置语言,主题等。我在设置主题时遇到问题。现在我有以下代码:
static void configureTheme(Activity activity, int defaultTheme) {
String theme = PreferenceManager.getDefaultSharedPreferences(activity).getString("theme", "light");
assert theme != null;
switch (theme) {
case "light":
activity.setTheme(R.style.AppTheme);
break;
case "dark":
activity.setTheme(R.style.Theme_AppCompat);
break;
default:
activity.setTheme(defaultTheme);
break;
}
}
Run Code Online (Sandbox Code Playgroud)
但是它崩溃了。我知道我应该使用super (of activity).setTheme而不是activity.setTheme,但是我该怎么做呢?如何将超类实例作为参数传递给静态方法?
我的目的是让用户选择图像:
fun launchChooseFileIntent(callerFragment: BaseFragment, REQUEST_CODE: Int) {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "image/*,"
}
startActivityForResult(intent, REQUEST_CODE)
}
Run Code Online (Sandbox Code Playgroud)
现在我需要用户可以选择图像和 pdf 文档。我尝试更改类型字符串,例如
type = "image/*,application/pdf"
Run Code Online (Sandbox Code Playgroud)
或者喜欢
type = "image/*|application/pdf"
Run Code Online (Sandbox Code Playgroud)
但它不起作用。
我也尝试添加额外的意图,例如
putExtra(Intent.EXTRA_MIME_TYPES, arrayOf("image/*", "application/pdf"))
Run Code Online (Sandbox Code Playgroud)
但应用程序崩溃了。
我该如何解决它?
我正在创建一个新的Android应用程序,但它在启动时崩溃(手机和模拟器).
这是代码:
Arcig Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tona.arcig"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="17" /><application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">
<activity android:name="MainActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Run Code Online (Sandbox Code Playgroud)
strings.xml中
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="suplovani">Suplování</string>
<string name="rozvrh">Rozvrh hodin</string>
<string name="prihlasovani">P?ihlašování do systému</string>
<string name="email">Email</string>
<string name="moodle">Moodle</string>
<string name="kdm">KDM</string>
<string name="o_aplikaci">O Aplikaci</string>
<string name="app_name">Arcig.CZ</string>
</resources>
Run Code Online (Sandbox Code Playgroud)
activity_main.xml中
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:contentDescription="@string/suplovani"
android:src="@drawable/suplovani" /> …Run Code Online (Sandbox Code Playgroud) android ×10
java ×3
crash ×1
date ×1
google-maps ×1
mime-types ×1
okhttp3 ×1
startup ×1
xml ×1