小编Cod*_*dey的帖子

应用程序关闭时广播接收器不工作

所以我制作了两个不同的应用程序,一个发送广播,另一个接收广播并显示祝酒词。但是,当我关闭接收器应用程序时,即使我在清单文件中定义了接收器,第二个应用程序也不再接收广播。

app1 的 MainActivity 中的广播发送者。

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button b = (Button)findViewById(R.id.button2);
    b.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent();
            i.setAction("com.example.ali.rrr");
            i.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
            sendBroadcast(i);
            Log.e("Broadcast","sent");
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

应用2广播接收器:

public class MyReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    // TODO: This method is called when the BroadcastReceiver is receiving
    // an Intent broadcast.
    Toast.makeText(context, "Broadcast has been recieved!", Toast.LENGTH_SHORT).show(); …
Run Code Online (Sandbox Code Playgroud)

java android broadcastreceiver android-intent

6
推荐指数
3
解决办法
1万
查看次数

发送短信权限不起作用

我想发送一条简单的消息,并且<uses-permission android:name="android.permission.SEND_SMS"/>我的清单中有,但我总是收到:java.lang.SecurityException: Sending SMS message: uid 10064 does not have android.permission.SEND_SMS.

我检查了这个答案,但它仍然不起作用。

这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.roa.sendsms" >


<uses-permission android:name="android.permission.SEND_SMS"/>

<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>
</application>
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

package com.roa.sendsms;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.telephony.SmsManager;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

@Override
protected …
Run Code Online (Sandbox Code Playgroud)

permissions sms android send android-manifest

5
推荐指数
1
解决办法
4万
查看次数

在多边形上找到最接近用户位置的点

我有一个应用程序,找到我的用户与多边形之间的最短距离.

我想将多边形转换为Geofence以检查用户与区域之间的距离,以便向用户提供准确的信息.

我怎样才能做到这一点?

这是MapsActivity

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, LocationListener, MinimumDistanceTask.GetMinimumDistanceListener {
    private GoogleMap mMap;
    private  LocationManager manager;
    private double lat, lng;
    private KmlLayer layer;
    private LatLng latLngTest;
    private  boolean contains = false;
    private  ArrayList<LatLng> outerBoundary;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
        manager = (LocationManager) getSystemService(LOCATION_SERVICE);
    }

    @Override
    protected void onResume() {
        super.onResume();
        String …
Run Code Online (Sandbox Code Playgroud)

android google-maps polygon android-geofence

3
推荐指数
1
解决办法
3556
查看次数

如何从android中的kml文件获取数组点

我有 kml 文件,并在我的地图中显示它KmlLayer。(它是在地图中显示的多边形形状)现在我需要检查用户位置是否在多边形中。如何获取多边形的坐标并检查用户是否在其中?

这是地图活动

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, LocationListener {

private GoogleMap mMap;
private  LocationManager manager;
private double lat, lng;
private KmlLayer layer;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
    manager = (LocationManager) getSystemService(LOCATION_SERVICE);

}

@Override
protected void onResume() {
    super.onResume();
    String provider = LocationManager.GPS_PROVIDER;

    try {
        manager.requestLocationUpdates(provider, 1000, 100, this);
    }catch …
Run Code Online (Sandbox Code Playgroud)

android google-maps polygon kml

2
推荐指数
1
解决办法
2122
查看次数