我想在一个单独的进程中启动一个服务(即当我在设置中转到我的应用程序管理器然后转到运行服务时,它应该在一个单独的进程中显示我的服务).
我的Android Manifest如下:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.timerapp.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>
<service android:name="com.example.timerapp.WorkerThread"
android:process="com.moizali"></service>
</application>
Run Code Online (Sandbox Code Playgroud)
我在MainActivity中启动服务,所以当我杀死应用程序时,服务也会关闭.任何人都可以告诉我如何将服务作为一个不同的过程启动.
我一直在尝试过去3天在默认的android消息视图中显示图形自定义图释.我已经成功地显示了我的自定义表情符号来代替键.现在的问题是我试图在spanable字符串构建器中显示drawable.但是drawable只是没有出现在键盘上.这是迄今为止的代码:
SpannableString ss = new SpannableString(" ");
Drawable d = getResources().getDrawable(R.drawable.a);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
// ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
ImageSpan span = new ImageSpan(d);
// ss.setSpan(span, 0, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
mComposing.append(":");
mComposing.setSpan(new ImageSpan(d), 0,1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
getCurrentInputConnection().commitText(mComposing, 1);
Run Code Online (Sandbox Code Playgroud)
我已经尝试了不同的方法以某种方式适合drawable但它只是不会显示在android的默认消息视图.任何帮助将受到高度赞赏.
我在Lollipop 5.0 Nexus上遇到此错误.
这就是我得到的
Fatal signal 11 (SIGSEGV), code 1 0x999e000c
Run Code Online (Sandbox Code Playgroud)
当我尝试使用Android的AudioRecorder类进行录制时,我收到此错误.
我使用NDK Stack来转储崩溃,我得到以下日志.
********** Crash dump: **********
Build fingerprint: 'google/hammerhead/hammerhead:5.0/LRX21O/1570415:user/release-keys'
pid: 1752, tid: 2184, name: pool-15-thread- >>> de.shopnow <<<
signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x9b6d2000
Stack frame #00 pc 00012f1c /system/lib/libc.so (__memcpy_base+95)
Stack frame #01 pc 000569b3 /system/lib/libmedia.so (android::AudioRecord::read(void*, unsigned int)+82)
Stack frame #02 pc 00095dbb /system/lib/libandroid_runtime.so
Stack frame #03 pc 00270fd7 /data/dalvik-cache/arm/system@framework@boot.oat
Run Code Online (Sandbox Code Playgroud)
有没有人经历过这个?
我正在使用AudioTrack播放我通过UDP套接字收到的声音.我和声音一起发出很多噪音,所以我决定使用AudioManager.但是AudioManager会将声音路由更改为超出应用程序的范围.以下是我正在使用的代码.
m_amAudioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
m_amAudioManager.setMode(AudioManager.MODE_IN_CALL);
m_amAudioManager.setSpeakerphoneOn(false);
Run Code Online (Sandbox Code Playgroud)
这段代码的问题在于,当我关闭应用程序并启动音乐播放器时,声音来自前置扬声器而不是后置扬声器,我不能以某种方式改变它.要解决此问题,我决定在关闭应用时添加以下行.
m_amAudioManager.setSpeakerphoneOn(true);
Run Code Online (Sandbox Code Playgroud)
但是对于这条线,问题是当我接到一个电话(正常通话)时,默认情况下扬声器开启.我真的需要帮助.
我正在使用Retrofit来使用Web服务,到目前为止它很棒.但Retrofit是否提供了从URL下载视频的方法?
我查看了此链接,但@Streaming
注释不再可用.复古适合图像下载
如果我在我的本地模拟器上运行仪器测试,它们完美地运行10次,但是当我尝试在Travis CI中的AVD上运行相同的测试时,我随机获得
FAILED java.lang.RuntimeException: Could not launch intent Intent { } within 45 seconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was xxxxxxx and now the last time the queue went idle was: …
我想选择一些电子邮件地址,然后向所有人发送电子邮件.
我的代码如下:
emailIntent .putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{listofemailaddresses});
emailIntent .putExtra(android.content.Intent.EXTRA_SUBJECT, "My Subject");
emailIntent .putExtra(android.content.Intent.EXTRA_TEXT, Constants.SMS_MESSAGE);
this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));`
Run Code Online (Sandbox Code Playgroud)
listofemailaddresses
是一个字符串,其中包含以","符号分隔的所有电子邮件.但是To字段在这里总是空的.
我正在使用Dagger注入RestAdapter.Builder,我正在该函数中创建一个OkHttpClient.功能如下:
@Provides
@Singleton
@Named("JSON")
public RestAdapter.Builder provideJsonRestAdapterBuilder(final ChangeableEndpoint changeableEndpoint,
final Set<RequestInterceptor> requestInterceptors) {
final OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setConnectTimeout(Constants.CONNECT_TIMEOUT, TimeUnit.SECONDS);
okHttpClient.setWriteTimeout(Constants.WRITE_TIMEOUT, TimeUnit.SECONDS);
okHttpClient.setReadTimeout(Constants.READ_TIMEOUT, TimeUnit.SECONDS);
try {
okHttpClient.setCache(new Cache(mApplication.getCacheDir(), Constants.CACHE_SIZE));
} catch (final IOException e) {
LOG.warn(e.getMessage(), e);
}
final Gson gson = new GsonBuilder()
.registerTypeAdapter(Date.class, new DateDeserializer())
.registerTypeAdapter(AbstractAction.class, new AbstractActionDeserializer())
.create();
return new RestAdapter.Builder()
.setLogLevel(BuildConfig.DEBUG ? RestAdapter.LogLevel.FULL : retrofit.RestAdapter.LogLevel.NONE)
.setConverter(new GsonConverter(gson))
.setEndpoint(changeableEndpoint)
.setClient(new OkClient(okHttpClient))
.setRequestInterceptor(new RequestInterceptor() {
@Override
public void intercept(final RequestFacade request) {
for (final RequestInterceptor requestInterceptor : …
Run Code Online (Sandbox Code Playgroud) 我可以看到,每当我进行 web svc 调用时,我都会在日志中得到响应。但是我发现很难在我的代码中实际访问这些信息。例如,我如何找出我可以从以下日志中看到的服务器请求时间和响应时间。
HTTP/1.1 200 OK
Connection: keep-alive
Content-Type: application/json;charset=UTF-8
Date: Tue, 21 Oct 2014 12:35:26 GMT
OkHttp-Received-Millis: 1413894922514
OkHttp-Response-Source: NETWORK 200
OkHttp-Selected-Protocol: http/1.1
OkHttp-Sent-Millis: 1413894921354
Server: Apache-Coyote/1.1
transfer-encoding: chunked
Run Code Online (Sandbox Code Playgroud) 我想知道是否可以获取仅存在于SIM卡或电话簿中的联系人.现在我正在使用以下代码来获取联系人,它甚至可以获取所有联系人以及我的Gmail和Facebook联系人.
Cursor cursor = getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI, null, null, null, Phone.DISPLAY_NAME + " ASC");
if (cursor.getCount() > 0)
{
while (cursor.moveToNext())
{
PhoneBookUserEntity user = new PhoneBookUserEntity();
// Pick out the ID, and the Display name of the
// contact from the current row of the cursor
user.setId(cursor.getString(cursor.getColumnIndex(BaseColumns._ID)));
user.setPhoneBookName(cursor.getString(cursor.getColumnIndex(
ContactsContract.Contacts.DISPLAY_NAME)));
if(user.getphonebookname().length() > 4)
username = user.getphonebookname();//.substring(0,4);
else
username = user.getphonebookname();//.substring(0,1);
String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
// if (Boolean.parseBoolean(hasPhone)) {
Cursor phones = getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ user.getId(), null, null); …
Run Code Online (Sandbox Code Playgroud)