我在意图中知道不同类型的标志但无法在我的活动中使用.任何人都可以解释我,
if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
mGoogleApiClient = new GoogleApiClient
.Builder(this)
.enableAutoManage(this, 34992, this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
locationChecker(mGoogleApiClient, this);
}
Run Code Online (Sandbox Code Playgroud)
我想在android gps关闭时看到gps对话框.但即使gps关闭,status.getStatusCode()
总是成功,我认为这是错误的.为什么?
public static void locationChecker(GoogleApiClient mGoogleApiClient, final Activity activity) {
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_NO_POWER);
//locationRequest.setInterval(864 * 1000);
//locationRequest.setFastestInterval(864 * 1000);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(locationRequest);
builder.setAlwaysShow(true);
PendingResult<LocationSettingsResult> result =
LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(LocationSettingsResult result) {
final Status status = result.getStatus();
final LocationSettingsStates state = result.getLocationSettingsStates();
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
// All …
Run Code Online (Sandbox Code Playgroud) 我正在创建一个应用程序,该程序可以通过编程方式更改应用程序图标和应用程序名称。
我已经实现了这一点,因为通过在Android清单中声明活动别名,只有5个名称和图标。
如果您只有5个名字,那么很容易在清单中声明它。但是,如果您不知道该怎么办。名称,您必须以编程方式更新清单。
下面是我的代码:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.drawerstack">
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity-alias android:label="@string/app_name1"
android:icon="@drawable/ic_launcher"
android:name=".MainActivity-Red"
android:enabled="false"
android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity-alias android:label="@string/app_name2"
android:icon="@drawable/ic_launcher_1"
android:name=".MainActivity-Pink"
android:enabled="false"
android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity-alias android:label="@string/app_name3"
android:icon="@drawable/ic_launcher_2"
android:name=".MainActivity-Blue"
android:enabled="false"
android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category …
Run Code Online (Sandbox Code Playgroud) 我希望在我的应用程序中,无论应用程序中发生什么,都可以播放音乐。我正在尝试使用Service
. 这是MyService.class
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
public class MyService extends Service implements MediaPlayer.OnPreparedListener {
MediaPlayer mMediaPlayer = null;
private static final String ACTION_PLAY = "com.example.action.PLAY";
public MyService() {
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent.getAction().equals(ACTION_PLAY)) {
mMediaPlayer = MediaPlayer.create(this, R.raw.theme_song);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.prepareAsync(); // prepare async to not …
Run Code Online (Sandbox Code Playgroud) 这可能是一个简单的问题,但我无法在数小时的搜索后找到解决方案.如何TextView
在下图中给出删除线效果.行长度应与文本长度相同.