在我的清单文件中,我已经声明了接收器.(如下)
<receiver android:name=".OnAlarmReceive" />
Run Code Online (Sandbox Code Playgroud)
但是,一旦我关闭了我的应用程序,我就无法收到警报和通知.显然,从来没有打过OnReceive
我的电话Broadcast receiver
.
public class OnAlarmReceive extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent arg1)
{
//various stuff
}
}
Run Code Online (Sandbox Code Playgroud)
在MainActivity中,我的警报管理器类如下所示.
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent intent = new Intent("MY_ALARM_NOTIFICATION");
intent.setClass(this, OnAlarmReceive.class);
intent.putExtra("message", message);
PendingIntent pendingIntent = PendingIntent
.getBroadcast(MainActivity.this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
Calendar timeCal = Calendar.getInstance();
timeCal.set(Calendar.HOUR_OF_DAY, hour);
timeCal.set(Calendar.MINUTE, minutes);
alarmManager.set(AlarmManager.RTC_WAKEUP, timeCal.getTimeInMillis(), pendingIntent);
Run Code Online (Sandbox Code Playgroud)
我的表现如下:
<receiver android:name=".OnAlarmReceive">
<intent-filter android:priority="1">
<action android:name="MY_ALARM_NOTIFICATION"/>
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
即使我关闭了我的应用程序,我该怎么做才能收到通知/警报.后台服务?
notifications android broadcastreceiver alarmmanager android-broadcast
我在做一个项目,我想整合GCM
和Google sign in
但问题是都有google-services.json
这就需要我们在我们的项目中添加的配置文件.
那么,我如何
google-services.json
在我的项目中集成两个配置文件.
这是我的配置文件之一
{
"project_info": {
"project_id": "default-xxx",
"project_number": "xxx",
"name": "xxx"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:xxx",
"client_id": "x.package",
"client_type": 1,
"android_client_info": {
"package_name": "x.package_name"
}
},
"oauth_client": [],
"api_key": [],
"services": {
"analytics_service": {
"status": 1
},
"cloud_messaging_service": {
"status": 1,
"apns_config": []
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"google_signin_service": {
"status": 1
},
"ads_service": {
"status": 1
}
}
}
],
"client_info": [], …
Run Code Online (Sandbox Code Playgroud) 我是新来的android
。我需要获得editText's
价值来搜索某些东西。但是当我运行程序时,错误出现在null pointer exception
.
“EditText etSearch”没有得到它的文本。
请帮我。谢谢。
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_search) {
AlertDialog.Builder builder = new AlertDialog.Builder(
MainActivity.this);
// Get the layout inflater
LayoutInflater inflater = MainActivity.this.getLayoutInflater();
// Inflate and set the layout for the dialog …
Run Code Online (Sandbox Code Playgroud) 我尝试一次录制2种不同分辨率的视频.有时一切顺利,有时应用程序似乎陷入2 MediaRecorders的stop()方法.有人可以查看我的代码,我做错了吗?
package com.example.android.videorecording;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.hardware.camera2.params.StreamConfigurationMap;
import android.media.MediaCodec;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.hardware.camera2.*;
import android.os.Environment;
import android.util.Size;
import android.view.Surface;
import android.view.View;
import android.widget.Button;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends Activity {
CameraDevice mCamera;
MediaRecorder mMediaRecorderLow = new MediaRecorder();
MediaRecorder mMediaRecorderHigh = new MediaRecorder();
CaptureRequest mCaptureRequest;
CameraCaptureSession mSession;
boolean recording = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CameraManager manager = (CameraManager) getSystemService(CAMERA_SERVICE);
File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() …
Run Code Online (Sandbox Code Playgroud) 我正在按照本教程ViewPager
在我的项目中实现.我已成功使用静态图像.现在我想更改它,以便从网址中检索图像并显示在其中ViewPager
.以下是我的代码.
我应该在哪里添加下载图像的方法以及如何将其设置为我的
ViewPager
?
任何帮助将不胜感激.
主要活动:
public class MainActivity extends AppCompatActivity {
private ArrayList<Integer> images;
private BitmapFactory.Options options;
private ViewPager viewPager;
private View btnNext, btnPrev;
private FragmentStatePagerAdapter adapter;
private LinearLayout thumbnailsContainer;
private final static int[] resourceIDs = new int[]{R.mipmap.a, R.mipmap.b,
R.mipmap.c, R.mipmap.d, R.mipmap.e, R.mipmap.f, R.mipmap.g};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
images = new ArrayList<>();
//find view by id
viewPager = (ViewPager) findViewById(R.id.view_pager);
thumbnailsContainer = (LinearLayout) findViewById(R.id.container);
btnNext = …
Run Code Online (Sandbox Code Playgroud) 我要救的ImageView
,我与展示setImageURI
在SDcard
我的Android设备中...
我怎样才能做到这一点?
码:
public class MainActivity extends ActionBarActivity {
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.imageView);
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Image"), 1);
}
});
}
@Override
protected void onActivityResult(int reqCode, int resCode, Intent data) {
if(resCode == RESULT_OK){
if(reqCode == 1)
imageView.setImageURI(data.getData());
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我正在开发一个项目,我必须显示帐户选择器,以便用户可以选择存储在其设备中的电子邮件帐户。问题是我已经AccountPicker.newChooseAccountIntent
弃用了。
是否有其他方法可以显示帐户选择器,而不是手动获取电子邮件并在自定义视图中显示它
现在我正在使用:
Intent googlePicker = AccountPicker.newChooseAccountIntent(null, null,
new String[] { GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE }, true, null, null, null, null);
startActivityForResult(googlePicker, PICK_ACCOUNT_REQUEST);
Run Code Online (Sandbox Code Playgroud) 我有两个java类和两个布局.每个布局都有一个按钮.这两个类都在扩展Activity
.现在在第一个布局中我使用了包含这样的标签
<include
android:id="@+id/clicked"
layout="@layout/activity_main" />
Run Code Online (Sandbox Code Playgroud)
我现在可以看到两个按钮,但第二个按钮不起作用.
我有一个数字EditText
的fragment
显示键盘为正常,当我选择EditText
.我想在输入OK时隐藏键盘.所以我使用了hide_keyboard()函数,它正常工作.
我遇到的问题是当我重新选择时EditText
,软键盘不再出现了.我尝试过很多东西,但都没有用.
有任何想法吗?
这是我的EditText:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="7"
android:id="@+id/kip_time"
android:hint="Reflexion time"
android:layout_below="@+id/chronometer_kipling"
android:layout_alignStart="@+id/chronometer_kipling"
android:layout_marginTop="10dp"
/>
Run Code Online (Sandbox Code Playgroud)
和我的hide_keyboard()函数:
private void hide_keyboard(Context context, View view) {
InputMethodManager inputManager = (InputMethodManager)
context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.toggleSoftInput(0, 0);
}
Run Code Online (Sandbox Code Playgroud)
最后我的onclicklistener方法:
kip_time.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
reflexion_time = Integer.parseInt(kip_time.getText().toString());
reflexion_time = reflexion_time * 1000;
hide_keyboard(context, view);
}
});
Run Code Online (Sandbox Code Playgroud) 我到处搜索但没有得到任何帮助.我想使用背景图像作为全屏幕,它将覆盖status bar
和footer navigation
具有back button
with home button
和a的task switcher button
.
如下图所示:
android android-layout android-6.0-marshmallow android-6.0.1-marshmallow