我需要在我的应用程序中连接我SeekBar的MediaPlayer。
我通过 xml 设置了 SeekBar,如下所示:
<SeekBar
android:id="@+id/song_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
Run Code Online (Sandbox Code Playgroud)
并按照这个SO 答案来实现它。
这是我的代码:
public class Song_main extends AppCompatActivity {
private final int SONG_REQUEST_CODE = 1;
private Uri song;
private TextView selectSong;
private SeekBar seekBar;
private Handler handler;
private MediaPlayer mediaPlayer;
private boolean repeatPressedTwice = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.app_bar_song_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.song_main_toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
seekBar = (SeekBar) findViewById(R.id.song_seekbar);
handler = new Handler();
notSelected();
}
@Override
public boolean onCreateOptionsMenu(Menu …Run Code Online (Sandbox Code Playgroud) For my App I need to have a List sync with Google Drive. I have already implemented the SignIn and had my Main_Activity implement both:
com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks,
com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener
Run Code Online (Sandbox Code Playgroud)
Even though I read the whole Google Drive API for Android documentation, and more specifically the Store Application Data part. And looked through the example on GitHub, I wasn't able to get it to work. I personally think that this documentation is really confusing to read. It's not even clear what is …
我知道有很多关于这个确切主题的问题,但是在花了两天时间阅读并尝试它们后,没有一个能够解决我的问题.
这是我的代码:
我发起了ACTION_GET_CONTENT我的onCreate()
Intent selectIntent = new Intent(Intent.ACTION_GET_CONTENT);
selectIntent.setType("audio/*");
startActivityForResult(selectIntent, AUDIO_REQUEST_CODE);
Run Code Online (Sandbox Code Playgroud)
检索Uri进入onActivityResult()
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == AUDIO_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
if ((data != null) && (data.getData() != null)) {
audio = data.getData();
}
}
}
Run Code Online (Sandbox Code Playgroud)
传递Uri给另一个活动并检索它
Intent debugIntent = new Intent(this, Debug.class);
Bundle bundle = new Bundle();
bundle.putString("audio", audio.toString());
debugIntent.putExtras(bundle);
startActivity(debugIntent);
Intent intent = this.getIntent();
Bundle bundle = …Run Code Online (Sandbox Code Playgroud) 我的应用有minSdk = 21和targetSdk = 26
我想设置应用程序快捷方式
我已将<meta-data>标记添加到应用启动时启动的第一个活动.
<activity android:name=".SignInActivity"
android:theme="@style/SubscriptionsTheme.NoActionBar">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts"/>
</activity>
Run Code Online (Sandbox Code Playgroud)
然后我创建了xml-v25目录,并在其中包含此shortcuts.xml文件:
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android" >
<shortcut
android:shortcutId="test"
android:icon="@drawable/plus"
android:shortcutShortLabel="test"
android:shortcutLongLabel="long test" >
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.xxxxx.xxxxx.xxxxx"
android:targetClass="com.xxxxx.xxxxx.xxxxxx.main" />
</shortcut>
</shortcuts>
Run Code Online (Sandbox Code Playgroud)
当我尝试构建应用程序时,我收到以下错误:
错误:错误:'long test'与属性android:shortcutLongLabel(attr)引用不兼容.错误:错误:'test'与属性android:shortcutShortLabel(attr)引用不兼容.错误:'long test'与属性android:shortcutLongLabel(attr)引用不兼容.
定义一个方法,给定一个二维整数数组,验证所有元素等于1构建一个矩形.
这就是我想到的:
public static boolean oneRectangle(int [][] a) {
boolean rectangle=true;
int[][] res;
int OneinRow=0; //keeps track of how many ones there are in the row
int OneinColoumn=0; //keeps track of how many ones there are in a coloumn
for(int i=0; i<a.length; i++) {
for (int j = 0; j < a[0].length; j++) {
while (a[i][j] == 1) {
i++;
OneinRow++;
}
while (a[i][j] == 1) {
j++;
OneinColoumn++;
}
}
}
res = new int[OneinRow][OneinColoumn];
for(int k=0; k<res.length; k++) …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用kotlin for android并试图像这样声明Linearlayout:
internal var linlay_SuccessfulPayment : LinearLayout = null!!
internal var linlay_failPayment : LinearLayout
linlay_SuccessfulPayment = findViewById(R.id.linlay_SuccessfulPayment) as LinearLayout
linlay_failPayment = findViewById(R.id.linlay_failPayment) as LinearLayout
Run Code Online (Sandbox Code Playgroud)
但是在日志中我得到了这个:
Caused by: kotlin.KotlinNullPointerException
at com.example.activities.PaymentResult.<init>(Result.kt:14)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1096)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3122)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
at android.app.ActivityThread.access$1100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7329)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Run Code Online (Sandbox Code Playgroud)
请帮帮我.
我在主屏幕中按住图标时尝试实现Android快捷方式.但是当我尝试启动它们时,我得到了一个
"App未安装"Toast
这是我的shortcuts.xml:
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:icon="@drawable/plus_black"
android:shortcutId="add_sub"
android:shortcutLongLabel="@string/shortcut_add_sub_long"
android:shortcutShortLabel="@string/shortcut_add_sub">
<intent
android:action="android.intent.action.VIEW"
android:targetClass="com.dancam.subscriptions.AddSubscription.AddSubscription"
android:targetPackage="com.dancam.subscriptions.AddSubscription" />
</shortcut>
<shortcut
android:icon="@drawable/pen"
android:shortcutId="create_sub"
android:shortcutLongLabel="@string/shortcut_create_sub_long"
android:shortcutShortLabel="@string/shortcut_create_sub">
<intent
android:action="android.intent.action.VIEW"
android:targetClass="com.dancam.subscriptions.CreateSubscription.CreateSubscription"
android:targetPackage="com.dancam.subscriptions.CreateSubscription" />
</shortcut>
</shortcuts>
Run Code Online (Sandbox Code Playgroud)
我已经看过这个问题,但我找不到合适的解决方案.
这是我的包/类树的样子:
关于如何解决这个问题的任何线索?
我正在尝试在我的 SettingsFragment 中添加一个 onPreferenceClickListener ,如果我这样做:
signOutPref.setOnPreferenceClickListener(object: Preference.OnPreferenceClickListener {
override fun onPreferenceClick(preference: Preference?): Boolean {
val signOutIntent = Intent(activity, SignInActivity::class.java)
startActivity(signOutIntent)
return true
}
})
Run Code Online (Sandbox Code Playgroud)
它在发出警告的同时完美运行:
使用属性访问语法
而如果我这样写:
signOutPref.setOnPreferenceClickListener {
val signOutIntent = Intent(activity, SignInActivity::class.java)
startActivity(signOutIntent)
return true
}
Run Code Online (Sandbox Code Playgroud)
这应该是完全相同的事情,这是最好的方法,我得到:
布尔文字不符合预期的类型 Unit
在return true声明上。
我错过了什么?第二种方法与第一种方法不同吗?我如何摆脱这个错误?
我已经成功实现了Google登录,它可以正常工作,并且在实际完成整个登录过程时也不会出现异常。
但是,如果我单击Google登录按钮,然后单击后退按钮以关闭该对话框,则我将收到以下错误消息:
造成原因:com.google.android.gms.tasks.RuntimeExecutionException:com.google.android.gms.common.api.ApiException:12501:位于com.google.android.gms.tasks.zzu.getResult(未知来源:17 )
这使我指向这段代码:
if (requestCode == RC_SIGN_IN) {
val task = GoogleSignIn.getSignedInAccountFromIntent(data)
try {
val account = task.result
firebaseAuthWithGoogle(account)
} catch (e: ApiException) {
Toast.makeText(this, "Google Sign In Failed", Toast.LENGTH_SHORT).show()
}
}
Run Code Online (Sandbox Code Playgroud)
特别是就val account = task.result行了。
我的问题是,它不应该通过自己处理catch并打印出吐司吗?为什么整个应用程序崩溃了?
这是我的全部SignInActivity:
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.design.widget.BottomSheetDialog
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.Toast
import com.dancam.subscriptions.ActiveSubscriptions.SubscriptionsMain
import com.dancam.subscriptions.R.id.google_signin_button
import com.dancam.subscriptions.R.id.signin_progressbar
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.gms.common.SignInButton
import com.google.android.gms.common.api.ApiException
import com.google.firebase.auth.FirebaseAuth …Run Code Online (Sandbox Code Playgroud) 在 Android 中设置通知时,从 Oreo 开始,您还需要设置一个 NotificationChannel
为了设置它,你需要给它一个name: String和一个description: String是可选的。
val name = "test channel"
val description = "test description"
val importance = NotificationManager.IMPORTANCE_DEFAULT
val channel = NotificationChannel("ID", name, importance)
channel.description = description
Run Code Online (Sandbox Code Playgroud)
根据文档,我无法弄清楚为什么需要输入这两个值,它们不会出现在 UI 中,即使在新的 Android P 测试版中也不会出现。
创建 NotificationChannel 时使用的名称和描述是什么?
编辑:
正如前两个答案所表明的那样,我在询问时可能不清楚。我知道是干什么NotificationChannel用的,我不清楚 name 和 description 属性是干什么用的。
我需要在我的recyclerView.
我曾经这样做过
View row = recyclerView.childAt(position);
Run Code Online (Sandbox Code Playgroud)
由于该childAt()方法基于ViewGroup,一旦滚动列表,位置就会混乱。
我在这里读到我必须使用recyclerView.findViewHolderForAdapterPosition()它返回一个ViewHolder.
我如何从我需要ViewHolder的实际View工作中获得?
在Kotlin我宣布List<String>这样:
private val items = listOf<String> {
"String1",
"String2",
"String3"
}
Run Code Online (Sandbox Code Playgroud)
编译器给我这个错误:
类型不匹配.
必需:字符串
找到:() - >字符串
这是什么意思?我如何解决它?
PS对Kotlin来说很新,所以请耐心等待一些明显的问题.