javascript

java

python

c#

node.js

android

reactjs

c++

php

jquery

html

css

git

ruby-on-rails

.net

ios

sql

c

string

ruby

android:屏幕和屏幕上的广播接收器

我只是想知道是否可以在应用程序清单中注册检测屏幕开/关的广播接收器。我不喜欢可编程方法的原因是,它需要运行应用程序才能检测到这种情况,而:“广播Intent以便接收者执行时,不必运行清单中已注册广播接收者的应用程序”(来源:Professional Android 2 Application Development book)

我的应用程序实际上是一个锁屏应用程序,它需要使用可编程方式一直运行:S

有办法解决吗?

我正在清单中尝试以下操作:

<receiver android:name=".MyBroadCastReciever">
    <intent-filter>
        <action android:name="android.intent.action.SCREEN_OFF"/>
        <action android:name="android.intent.action.SCREEN_ON"/>
    </intent-filter>
</receiver>

和简单的BroadCastReceiver类:

public class MyBroadCastReciever extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
            Log.i("Check","Screen went OFF");
            Toast.makeText(context, "screen OFF",Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
            Log.i("Check","Screen went ON");
            Toast.makeText(context, "screen ON",Toast.LENGTH_LONG).show();
        }
    }
}
trans by 2019-10-09T18:04:58Z

android-服务意图必须明确:意图

我现在有一个应用程序,通过广播接收器(MyStartupIntentReceiver)调用服务。 为了调用该服务,广播接收器中的代码是:

public void onReceive(Context context, Intent intent) {
    Intent serviceIntent = new Intent();
    serviceIntent.setAction("com.duk3r.eortologio2.MyService");
    context.startService(serviceIntent);
}

问题是,在Android 5.0 Lollipop中,出现以下错误(在早期版本的Android中,一切正常):

Unable to start receiver com.duk3r.eortologio2.MyStartupIntentReceiver: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.duk3r.eortologio2.MyService }

为了将服务声明为显式且正常启动,我必须更改什么? 在其他类似线程中尝试了一些答案,但是尽管我摆脱了该消息,但该服务无法启动。

trans by 2019-10-08T18:34:09Z

android-如何确定我的活动之一是否在前台

这个问题在这里已有答案:

  • 检查Android应用程序是否在后台运行                                     29个答案

我已经实现了由AlarmManager触发的BroadcastReceiver。 AlarmManager在BOOT_COMPLETED上初始化。 因此,我必须在清单中声明接收方。

我的问题是,我只希望在我自己的活动都不在前台(也就是用户未与我的应用程序进行交互)时才执行BroadcastReceiver。 我从远程服务器提取信息,并且无论如何都不想通知用户。

到目前为止,我还没有找到一种方法来确定我的应用程序是否在前台。 有办法做这种事吗? ActivityManager会告诉我我的应用程序是否正在运行,但不会告诉我它是否在前台。

问题与这里描述的几乎相同:仅当它在前台时才从BroadcastReceiver通知活动

解:

在评估了几种解决方案之后,我想快速概述一下我认为是处理背景/前景活动的最佳方法。

首选方法是在活动的onResume方法中注册广播接收器,并在onPause的活动中注销它。 任何服务或其他背景元素都将需要发送广播意图,其中包含您的活动将拦截的特定操作。

如果您的活动处于前台,它将注册其意图接收器,并能够直接处理您的服务发送的意图。 如果它不在前台,它将不会接收到该意图,但是调用广播的服务将知道没有人截获其广播意图,并且能够自行处理。 例如,它可以启动所需的活动,显示通知等。

trans by 2019-10-08T09:09:58Z

Android,检测其他应用程序何时启动

我正在尝试开发一个应用程序,防止用户在没有密码的情况下访问指定的应用程序。 情景是......

  1. 用户点击“电子邮件”应用(例如)
  2. 我的应用检测到应用的启动
  3. 我的应用程序确认它是“电子邮件”应用程序
  4. 我的应用程序在顶部打开一个视图,要求输入密码
  5. 用户输入密码,如果正确,我的应用程序将消失,将“电子邮件”应用程序保留在最顶层

我正在做剩下的事情,只是第2部分令我感到困惑,经过多天阅读广播意图等并试图在我的试验项目中听“android.intent.action.MAIN”等我不能 似乎检测到我的应用程序何时启动。

有人可以帮忙吗? 我是否正确地寻找新的应用程序广播意图启动,或者我应该阅读系统日志以获取新意图,或者使用本机代码执行某些操作?

任何指针都会有所帮助,即使你无法完全回答它,我也可以做更多的研究。 非常感谢。伊恩

trans by 2019-09-10T22:14:27Z

java - Android - 在b上启动服务

从我在Stack Exchange和其他地方看到的所有内容中,我已经正确设置了所有内容,以便在Android OS启动时启动IntentService。 不幸的是,它不是在启动时启动,而且我没有收到任何错误。 也许专家可以提供帮助......

表现:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.phx.batterylogger"
  android:versionCode="1"
  android:versionName="1.0"
  android:installLocation="internalOnly">

<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BATTERY_STATS" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <service android:name=".BatteryLogger"/>
    <receiver android:name=".StartupIntentReceiver">  
        <intent-filter>  
            <action android:name="android.intent.action.BOOT_COMPLETED" />  
        </intent-filter>  
    </receiver>
</application>

</manifest>

BroadcastReceiver for Startup:

package com.phx.batterylogger;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class StartupIntentReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Intent serviceIntent = new Intent(context, BatteryLogger.class);
        context.startService(serviceIntent);
    }
}

更新:我尝试了下面的所有建议,并且我将诸如Log.v("BatteryLogger", "Got to onReceive, about to start service");的日志记录添加到StartupIntentReceiver的onReceive处理程序中,并且没有记录任何内容。 所以它甚至没有进入BroadcastReceiver。

我想我正在部署APK并正确测试,只需在Eclipse中运行Debug,控制台就说它成功将它安装到我的Xoom平板电脑\ BatteryLogger \ bin \ BatteryLogger.apk。 然后进行测试,我重新启动平板电脑,然后查看DDMS中的日志,并在操作系统设置中检查正在运行的服务。 这听起来是否正确,或者我错过了什么? 再次,非常感谢任何帮助。

trans by 2019-08-25T13:33:53Z

android - 有多个过滤器或多个BroadcastReceivers的BroadcastReceiver?

我有一个需要捕获两个不同广播的Android活动。 我目前的方法是在Activity中有一个onCreate并用它来捕获两个广播:

public class MyActivity extends Activity {
    private MyActivity.BroadcastListener mBroadcastListener;
    private boolean mIsActivityPaused = false;

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

        // Create the broadcast listener and register the filters
        mIsActivityPaused = false;
        mBroadcastListener = new BroadcastListener();

        IntentFilter filter = new IntentFilter();
        filter.addAction(Params.INTENT_REFRESH);
        filter.addAction(Params.INTENT_UPDATE);
        registerReceiver(mBroadcastListener, filter);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mIsActivityPaused = false;
    }

    @Override
    protected void onPause() {
        super.onPause();
        mIsActivityPaused = true;
    }

    @Override
    protected void onDestroy() {
        unregisterReceiver(mBroadcastListener);
        super.onDestroy();
    }

    private void refresh() {
        // refresh
    }

    private void update() {
        // update
    }

    private class BroadcastListener extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Params.INTENT_REFRESH && !mIsActivityPaused)) {
                refresh();
            } else if (intent.getAction().equals(Params.INTENT_UPDATE)) {
                update();
            }
        }
    }
}

我想仅在我的活动在屏幕上可见时执行onCreate,但我想在活动的整个生命周期内捕获INTENT_REFRESH并执行update(),无论活动是否可见。

我没有找到任何方法只注销我在onCreate中注册的两个过滤器中的一个,所以我使用一个标志来启用或禁用捕获INTENT_REFRESH广播时要执行的操作,具体取决于活动的状态。

问题是:这是正确的方法吗?

或者,最好有两个单独的BroadcastReceivers,如下所示:

public class MyActivity extends Activity {
    private MyActivity.BroadcastListenerRefresh mBroadcastListenerRefresh;
    private MyActivity.BroadcastListenerUpdate mBroadcastListenerUpdate;
    private boolean mIsBroadcastListenerRefreshRegistered = false;

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

        // Create the broadcast listeners
        mBroadcastListenerRefresh = new BroadcastListenerRefresh();
        mBroadcastListenerUpdate = new BroadcastListenerUpdate();

        registerReceiver(mBroadcastListenerRefresh, new IntentFilter(Params.INTENT_REFRESH));
        registerReceiver(mBroadcastListenerUpdate, new IntentFilter(Params.INTENT_UPDATE));
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (mBroadcastListenerRefresh != null && !mIsBroadcastListenerRefreshRegistered) {
            registerReceiver(mBroadcastListenerRefresh, new IntentFilter(Params.INTENT_REFRESH));
            mIsBroadcastListenerRefreshRegistered = true;
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (mBroadcastListenerRefresh != null && mIsBroadcastListenerRefreshRegistered) {
            unregisterReceiver(mBroadcastListenerRefresh);
            mIsBroadcastListenerRefreshRegistered = false;
        }
    }

    @Override
    protected void onDestroy() {
        unregisterReceiver(mBroadcastListenerRefresh);
        unregisterReceiver(mBroadcastListenerUpdate);
        super.onDestroy();
    }

    private void refresh() {
        // refresh
    }

    private void update() {
        // update
    }

    private class BroadcastListenerRefresh extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Params.INTENT_REFRESH)) {
                refresh();
            }
        }
    }

    private class BroadcastListenerUpdate extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Params.INTENT_UPDATE)) {
                update();
            }
        }
    }
}

哪一个有更好的表现?

trans by 2019-08-05T00:16:08Z

android - Receiver没有注册异常错误?

在我的开发者控制台中,人们不断报告我无法在任何手机上重现的错误。 一个人留言说他在试图打开我的电池服务的设置屏幕时得到它。 从错误中可以看出,它表示接收器未注册。

java.lang.RuntimeException: Unable to stop service .BatteryService@4616d688:  java.lang.IllegalArgumentException: Receiver not registered: com.app.notifyme.BatteryService$BatteryNotifyReceiver@4616d9d0
at android.app.ActivityThread.handleStopService(ActivityThread.java:3164)
at android.app.ActivityThread.access$3900(ActivityThread.java:129)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2173)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: Receiver not registered:com..BatteryService$BatteryNotifyReceiver@4616d9d0
at android.app.ActivityThread$PackageInfo.forgetReceiverDispatcher(ActivityThread.java:805)
at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:859)
at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:331)
at com.app.notifyme.BatteryService.onDestroy(BatteryService.java:128)
at android.app.ActivityThread.handleStopService(ActivityThread.java:3150)

我注册的是我的onCreate

@Override
public void onCreate(){
    super.onCreate();
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
    IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    filter.addAction(Intent.ACTION_POWER_CONNECTED);
    filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
    registerReceiver(batteryNotifyReceiver,filter);
    pref.registerOnSharedPreferenceChangeListener(this);
}

取消注册onDestroy以及首选项侦听器

    @Override
public void onDestroy(){
    super.onDestroy();
    unregisterReceiver(batteryNotifyReceiver);

}

这是我服务的接收者

private final class BatteryNotifyReceiver extends BroadcastReceiver {

    boolean connected;
    @Override
    public void onReceive(Context context, Intent intent) {

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); 
        SharedPreferences.Editor edit = prefs.edit();

            updatePreferences(prefs);

        level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);



        if(intent.getAction().equals(Intent.ACTION_POWER_CONNECTED)){
            connected = true;
        }else if(intent.getAction().equals(Intent.ACTION_POWER_DISCONNECTED)){
            connected = false;
        }else if(intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)){

                if(level < lastLevel){
                    if(level > 40){
                        edit.putBoolean("first", false).commit();
                        edit.putBoolean("second", false).commit();
                        edit.putBoolean("third", false).commit();
                       edit.putBoolean("fourth",false).commit();                            
                        edit.putBoolean("fifth", false).commit();
                    }
                    if(level == 40){
                        if(!first){
                        notification(context,battColor,battBlink,battVib,battSound);

                        edit.putBoolean("first", true).commit();
                        }
                    }else if(level == 30){
                        if(!second){
                        notification(context,battColor,battBlink,battVib,battSound);

                        edit.putBoolean("second", true).commit();
                        }
                    }else if(level == 20){
                        if(!third){
                        notification(context,battColor,battBlink,battVib,battSound);

                        edit.putBoolean("third", true).commit();
                        }
                    }else if(level == 15){
                        if(!fourth){
                        notification(context,battColor,battBlink,battVib,battSound);

                        edit.putBoolean("fourth", true).commit();
                        }
                    }else if(level == 5){
                        if(!fifth){
                        notification(context,battColor,battBlink,battVib,battSound);

                        edit.putBoolean("fifth", true).commit();
                        }
                    }
                lastLevel = temp;
            }
        }           

        Intent i = new Intent(context,BatteryNotifyReceiver.class);
        context.startService(i);
    }       
}

知道他们为什么会得到那个错误吗?

trans by 2019-07-17T13:04:22Z

在Android中发送和接收短信和彩信(pre Kit Kat Android 4.4)

我已经弄明白了如何发送和接收短信。 要发送短信,我不得不拨打You have to add jsoup to the build path, the jar to the build path and import com.droidprism.*; To do that in android, add the jars to the libs directory first, then configure the project build path to use the jars already in the libs directory, then on the build path config click order and export and check the boxes of the jars and move jsoup and droidprism jar to the top of the build order.getMMSApns()类的getMMSApns()方法。 要接收SMS消息,我必须在ContentObserver文件中注册接收器。 然后我不得不覆盖BroadcastReceiveronReceive()方法。我在下面列举了一些例子。

MainActivity.java

public class MainActivity extends Activity {
    private static String SENT = "SMS_SENT";
    private static String DELIVERED = "SMS_DELIVERED";
    private static int MAX_SMS_MESSAGE_LENGTH = 160;

    // ---sends an SMS message to another device---
    public static void sendSMS(String phoneNumber, String message) {

        PendingIntent piSent = PendingIntent.getBroadcast(mContext, 0, new Intent(SENT), 0);
        PendingIntent piDelivered = PendingIntent.getBroadcast(mContext, 0,new Intent(DELIVERED), 0);
        SmsManager smsManager = SmsManager.getDefault();

        int length = message.length();          
        if(length > MAX_SMS_MESSAGE_LENGTH) {
            ArrayList<String> messagelist = smsManager.divideMessage(message);          
            smsManager.sendMultipartTextMessage(phoneNumber, null, messagelist, null, null);
        }
        else
            smsManager.sendTextMessage(phoneNumber, null, message, piSent, piDelivered);
        }
    }

    //More methods of MainActivity ...
}

SMSReceiver.java

public class SMSReceiver extends BroadcastReceiver {
    private final String DEBUG_TAG = getClass().getSimpleName().toString();
    private static final String ACTION_SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
    private Context mContext;
    private Intent mIntent;

    // Retrieve SMS
    public void onReceive(Context context, Intent intent) {
        mContext = context;
        mIntent = intent;

        String action = intent.getAction();

        if(action.equals(ACTION_SMS_RECEIVED)){

            String address, str = "";
            int contactId = -1;

            SmsMessage[] msgs = getMessagesFromIntent(mIntent);
            if (msgs != null) {
                for (int i = 0; i < msgs.length; i++) {
                    address = msgs[i].getOriginatingAddress();
                    contactId = ContactsUtils.getContactId(mContext, address, "address");
                    str += msgs[i].getMessageBody().toString();
                    str += "\n";
                }
            }   

            if(contactId != -1){
                showNotification(contactId, str);
            }

            // ---send a broadcast intent to update the SMS received in the
            // activity---
            Intent broadcastIntent = new Intent();
            broadcastIntent.setAction("SMS_RECEIVED_ACTION");
            broadcastIntent.putExtra("sms", str);
            context.sendBroadcast(broadcastIntent);
        }

    }

    public static SmsMessage[] getMessagesFromIntent(Intent intent) {
        Object[] messages = (Object[]) intent.getSerializableExtra("pdus");
        byte[][] pduObjs = new byte[messages.length][];

        for (int i = 0; i < messages.length; i++) {
            pduObjs[i] = (byte[]) messages[i];
        }
        byte[][] pdus = new byte[pduObjs.length][];
        int pduCount = pdus.length;
        SmsMessage[] msgs = new SmsMessage[pduCount];
        for (int i = 0; i < pduCount; i++) {
            pdus[i] = pduObjs[i];
            msgs[i] = SmsMessage.createFromPdu(pdus[i]);
        }
        return msgs;
    }

    /**
    * The notification is the icon and associated expanded entry in the status
    * bar.
    */
    protected void showNotification(int contactId, String message) {
        //Display notification...
    }
}

AndroidManifest.xml中

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

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.SEND_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.WRITE_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_MMS" />
    <uses-permission android:name="android.permission.WRITE" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:debuggable="true"
        android:icon="@drawable/ic_launcher_icon"
        android:label="@string/app_name" >

        <activity
            //Main activity...
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            //Activity 2 ...
        </activity>
        //More acitivies ...

        // SMS Receiver
        <receiver android:name="com.myexample.receivers.SMSReceiver" >
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>

    </application>
</manifest>

但是,我想知道你是否可以以类似的方式发送和接收彩信。 在做了一些研究之后,博客上提供的许多示例只是将You have to add jsoup to the build path, the jar to the build path and import com.droidprism.*; To do that in android, add the jars to the libs directory first, then configure the project build path to use the jars already in the libs directory, then on the build path config click order and export and check the boxes of the jars and move jsoup and droidprism jar to the top of the build order.传递给本机Messaging应用程序。 我试图在不离开我的申请的情况下发送彩信。 似乎没有标准的发送和接收MMS的方式。 有没有人得到这个工作?

此外,我知道SMS / MMS ContentProvider不是官方Android SDK的一部分,但我认为有人可能已经能够实现这一点。 任何帮助是极大的赞赏。

更新

我在getMMSApns()文件中添加了You have to add jsoup to the build path, the jar to the build path and import com.droidprism.*; To do that in android, add the jars to the libs directory first, then configure the project build path to use the jars already in the libs directory, then on the build path config click order and export and check the boxes of the jars and move jsoup and droidprism jar to the top of the build order.以接收彩信

<receiver android:name="com.sendit.receivers.MMSReceiver" >
    <intent-filter>
        <action android:name="android.provider.Telephony.WAP_PUSH_RECEIVED" />

        <data android:mimeType="application/vnd.wap.mms-message" />
    </intent-filter>
</receiver>

在MMSReceiver类中,You have to add jsoup to the build path, the jar to the build path and import com.droidprism.*; To do that in android, add the jars to the libs directory first, then configure the project build path to use the jars already in the libs directory, then on the build path config click order and export and check the boxes of the jars and move jsoup and droidprism jar to the top of the build order.方法只能获取发送消息的phoneNumber。 你如何从MMS中获取其他重要信息,例如媒体附件(图像/音频/视频)的文件路径或MMS中的文本?

MMSReceiver.java

public class MMSReceiver extends BroadcastReceiver {
    private final String DEBUG_TAG = getClass().getSimpleName().toString();
    private static final String ACTION_MMS_RECEIVED = "android.provider.Telephony.WAP_PUSH_RECEIVED";
    private static final String MMS_DATA_TYPE = "application/vnd.wap.mms-message";

     // Retrieve MMS
    public void onReceive(Context context, Intent intent) {

        String action = intent.getAction();
        String type = intent.getType();

        if(action.equals(ACTION_MMS_RECEIVED) && type.equals(MMS_DATA_TYPE)){

            Bundle bundle = intent.getExtras();

            Log.d(DEBUG_TAG, "bundle " + bundle);
            SmsMessage[] msgs = null;
            String str = "";
            int contactId = -1;
            String address;

            if (bundle != null) {

                byte[] buffer = bundle.getByteArray("data");
                Log.d(DEBUG_TAG, "buffer " + buffer);
                String incomingNumber = new String(buffer);
                int indx = incomingNumber.indexOf("/TYPE");
                if(indx>0 && (indx-15)>0){
                    int newIndx = indx - 15;
                    incomingNumber = incomingNumber.substring(newIndx, indx);
                    indx = incomingNumber.indexOf("+");
                    if(indx>0){
                        incomingNumber = incomingNumber.substring(indx);
                        Log.d(DEBUG_TAG, "Mobile Number: " + incomingNumber);
                    }
                }

                int transactionId = bundle.getInt("transactionId");
                Log.d(DEBUG_TAG, "transactionId " + transactionId);

                int pduType = bundle.getInt("pduType");
                Log.d(DEBUG_TAG, "pduType " + pduType);

                byte[] buffer2 = bundle.getByteArray("header");      
                String header = new String(buffer2);
                Log.d(DEBUG_TAG, "header " + header);

                if(contactId != -1){
                    showNotification(contactId, str);
                }

                // ---send a broadcast intent to update the MMS received in the
                // activity---
                Intent broadcastIntent = new Intent();
                broadcastIntent.setAction("MMS_RECEIVED_ACTION");
                broadcastIntent.putExtra("mms", str);
                context.sendBroadcast(broadcastIntent);

            }
        }

    }

    /**
    * The notification is the icon and associated expanded entry in the status
    * bar.
    */
    protected void showNotification(int contactId, String message) {
        //Display notification...
    }
}

根据android.provider.Telephony的文档:

广播操作:设备已收到新的基于文本的SMS消息。 意图将具有以下额外值:

You have to add jsoup to the build path, the jar to the build path and import com.droidprism.*; To do that in android, add the jars to the libs directory first, then configure the project build path to use the jars already in the libs directory, then on the build path config click order and export and check the boxes of the jars and move jsoup and droidprism jar to the top of the build order. - getMMSApns()APNHelpers,其中包含组成消息的PDU。

可以使用You have to add jsoup to the build path, the jar to the build path and import com.droidprism.*; To do that in android, add the jars to the libs directory first, then configure the project build path to use the jars already in the libs directory, then on the build path config click order and export and check the boxes of the jars and move jsoup and droidprism jar to the top of the build order.提取额外值   如果BroadcastReceiver在处理此意图时遇到错误,则应该适当地设置结果代码。

You have to add jsoup to the build path, the jar to the build path and import com.droidprism.*; To do that in android, add the jars to the libs directory first, then configure the project build path to use the jars already in the libs directory, then on the build path config click order and export and check the boxes of the jars and move jsoup and droidprism jar to the top of the build order.

广播操作:设备已收到新的基于数据的SMS消息。 意图将具有以下额外值:

You have to add jsoup to the build path, the jar to the build path and import com.droidprism.*; To do that in android, add the jars to the libs directory first, then configure the project build path to use the jars already in the libs directory, then on the build path config click order and export and check the boxes of the jars and move jsoup and droidprism jar to the top of the build order. - getMMSApns()APNHelpers,其中包含组成消息的PDU。

可以使用getMessagesFromIntent(android.content.Intent)提取额外值。   如果BroadcastReceiver在处理此意图时遇到错误,则应该适当地设置结果代码。

You have to add jsoup to the build path, the jar to the build path and import com.droidprism.*; To do that in android, add the jars to the libs directory first, then configure the project build path to use the jars already in the libs directory, then on the build path config click order and export and check the boxes of the jars and move jsoup and droidprism jar to the top of the build order.

广播操作:设备已收到新的WAP PUSH消息。 意图将具有以下额外值:

You have to add jsoup to the build path, the jar to the build path and import com.droidprism.*; To do that in android, add the jars to the libs directory first, then configure the project build path to use the jars already in the libs directory, then on the build path config click order and export and check the boxes of the jars and move jsoup and droidprism jar to the top of the build order. - WAP交易ID

You have to add jsoup to the build path, the jar to the build path and import com.droidprism.*; To do that in android, add the jars to the libs directory first, then configure the project build path to use the jars already in the libs directory, then on the build path config click order and export and check the boxes of the jars and move jsoup and droidprism jar to the top of the build order. - WAP PDU类型`

You have to add jsoup to the build path, the jar to the build path and import com.droidprism.*; To do that in android, add the jars to the libs directory first, then configure the project build path to use the jars already in the libs directory, then on the build path config click order and export and check the boxes of the jars and move jsoup and droidprism jar to the top of the build order. - 消息的标题

You have to add jsoup to the build path, the jar to the build path and import com.droidprism.*; To do that in android, add the jars to the libs directory first, then configure the project build path to use the jars already in the libs directory, then on the build path config click order and export and check the boxes of the jars and move jsoup and droidprism jar to the top of the build order. - 消息的数据有效负载

You have to add jsoup to the build path, the jar to the build path and import com.droidprism.*; To do that in android, add the jars to the libs directory first, then configure the project build path to use the jars already in the libs directory, then on the build path config click order and export and check the boxes of the jars and move jsoup and droidprism jar to the top of the build order. - 与内容类型关联的任何参数(从WSP Content-Type标头解码)

如果BroadcastReceiver在处理此意图时遇到错误,则应该适当地设置结果代码。   contentTypeParameters额外值是按名称键入的内容参数的映射。   如果遇到任何未分配的已知参数,则映射的键将为“unassigned / 0x ...”,其中“...”是未分配参数的十六进制值。 如果参数具有无值,则映射中的值将为null。

You have to add jsoup to the build path, the jar to the build path and import com.droidprism.*; To do that in android, add the jars to the libs directory first, then configure the project build path to use the jars already in the libs directory, then on the build path config click order and export and check the boxes of the jars and move jsoup and droidprism jar to the top of the build order.

更新#2

我已经想出如何通过You have to add jsoup to the build path, the jar to the build path and import com.droidprism.*; To do that in android, add the jars to the libs directory first, then configure the project build path to use the jars already in the libs directory, then on the build path config click order and export and check the boxes of the jars and move jsoup and droidprism jar to the top of the build order.传递额外内容以获得getMMSApns():Android PendingIntent附加功能,未被BroadcastReceiver接收

但是,额外的传递给SendBroadcastReceiver而不是SMSReceiver。 如何将额外的内容传递给SMSReceiver?

更新#3

接收彩信

所以在做了更多的研究之后,我看到了一些注册You have to add jsoup to the build path, the jar to the build path and import com.droidprism.*; To do that in android, add the jars to the libs directory first, then configure the project build path to use the jars already in the libs directory, then on the build path config click order and export and check the boxes of the jars and move jsoup and droidprism jar to the top of the build order.的建议。这样你就可以检测到getMMSApns()内容提供商有什么变化,从而允许你检测传入的彩信。 以下是我发现的最接近的示例:接收彩信

但是,有一个变量You have to add jsoup to the build path, the jar to the build path and import com.droidprism.*; To do that in android, add the jars to the libs directory first, then configure the project build path to use the jars already in the libs directory, then on the build path config click order and export and check the boxes of the jars and move jsoup and droidprism jar to the top of the build order.类型为getMMSApns().APNHelper类在哪里实现? 是否有注册ContentObserver的其他任何实现?

发送彩信

至于发送彩信,我遇到过这个例子:发送彩信

问题是我尝试在我的Nexus 4上运行此代码,这是在Android v4.2.2上,我收到此错误:

java.lang.SecurityException: No permission to write APN settings: Neither user 10099 nor current process has android.permission.WRITE_APN_SETTINGS.

APNHelper类的getMMSApns()方法中查询You have to add jsoup to the build path, the jar to the build path and import com.droidprism.*; To do that in android, add the jars to the libs directory first, then configure the project build path to use the jars already in the libs directory, then on the build path config click order and export and check the boxes of the jars and move jsoup and droidprism jar to the top of the build order. ContentProvider后,将引发错误。

final Cursor apnCursor = this.context.getContentResolver().query(Uri.withAppendedPath(Carriers.CONTENT_URI, "current"), null, null, null, null);

显然你无法在Android 4.2中阅读APN

对于使用移动数据执行操作(如发送MMS)并且不知道设备中存在默认APN设置的所有应用程序,有哪些替代方案?

更新#4

发送彩信

我试过这个例子:发送彩信

正如@Sam在他的回答中建议的那样:

You have to add jsoup to the build path, the jar to the build path and import com.droidprism.*; To do that in android, add the jars to the libs directory first, then configure the project build path to use the jars already in the libs directory, then on the build path config click order and export and check the boxes of the jars and move jsoup and droidprism jar to the top of the build order.

所以现在我不再收到SecurityException错误。 我正在测试Android KitKat上的Nexus 5。 运行示例代码后,它会在调用后给出200响应代码

MMResponse mmResponse = sender.send(out, isProxySet, MMSProxy, MMSPort);

但是,我检查过我尝试发送彩信的人。 他们说他们从未收到彩信。

trans by 2019-06-01T08:58:24Z

service - Android - 从广播接收器onReceive()获取上下文发送

我基本上想要创建一个intent并将它传递给我的BroadcastReceiver的onReceive()服务。

到目前为止,我总是使用View.getContext(),但在这里,我被卡住了。我怎么能得到上下文所以我可以使用public Intent (Context packageContext, Class<?> cls)

trans by 2019-05-20T08:34:57Z

api - 如何检查Receiver是否在Android中注册?

我需要检查我的注册接收者是否仍然注册,如果不是我如何检查任何方法?

trans by 2019-04-04T18:50:59Z

android - 如何使用LocalBroadcastManager?

如何使用/定位LocalBroadcastManager,如谷歌文档和服务广播文档中所述?

我试图谷歌它,但没有可用的代码开始?

文件说如果我想在我的应用程序进程内部进行广播,我应该使用它,但我不知道在哪里寻找这个。

任何帮助/评论?

更新:我知道如何使用广播,但不知道如何在我的项目中获得LocalBroadcastManager

trans by 2019-03-30T19:39:40Z

android - Servi中的广播接收器

我想在Service内启动BroadcastReceiver。我要做的是运行后台运行service,收集传入的短信,并记录来电。 我认为最好的方法是运行service,它包含一个可以编目的广播接收器。

我该怎么做呢? 我已经启动并运行了我的服务。

trans by 2019-03-30T07:48:43Z

java - 在Android应用程序中检查互联网连接的广播接收器

我正在开发一个用于检查互联网连接的android广播接收器。

问题是我的广播接收器被调用了两次。 我希望它只在网络可用时才被调用。 如果它不可用,我不希望得到通知。

这是广播接收器

public class NetworkChangeReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(final Context context, final Intent intent) {
        final ConnectivityManager connMgr = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);

        final android.net.NetworkInfo wifi = connMgr
                .getNetworkInfo(ConnectivityManager.TYPE_WIFI);

        final android.net.NetworkInfo mobile = connMgr
                .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

        if (wifi.isAvailable() || mobile.isAvailable()) {
            // Do something

            Log.d("Network Available ", "Flag No 1");
        }
    }
}

这是manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.broadcastreceiverforinternetconnection"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <receiver android:name=".NetworkChangeReceiver" >
            <intent-filter>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
                <action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
            </intent-filter>
        </receiver>
    </application>

</manifest>
trans by 2019-03-21T11:24:20Z

android - 如何在启动时启动我的应用程序?

我尝试在此链接中使用示例代码,但它似乎已过时,但它不起作用。 那么当Android完成启动时,我需要做些什么更改以及让我的应用自动启动哪些文件?

trans by 2019-03-10T01:18:42Z

android - 在Servi中获取上下文

有没有可靠的方法从registerReceiver()获得Context

我想为Context注册广播接收器,但我不需要我的应用程序总是得到这些信息,所以我不把它放在registerReceiver()

但是,当我需要这些信息时,我不能让GC杀死广播接收器,因此我在Context中注册了广播接收器。

因此,我需要Context来拨打registerReceiver()。  当我不再需要ACTION_PHONE_STATE_CHANGED时,我取消注册它。

有小费吗?

trans by 2019-03-01T07:31:01Z

broadcastreceiver - 尝试在Android上启动服务

当设备在Android上启动时,我一直在尝试启动服务,但我无法让它工作。 我在网上看了很多链接,但没有一个代码可以工作。 我忘记了什么吗?

AndroidManifest.xml中

<receiver
    android:name=".StartServiceAtBootReceiver"
    android:enabled="true"
    android:exported="false"
    android:label="StartServiceAtBootReceiver" >
    <intent-filter>
        <action android:name="android.intent.action._BOOT_COMPLETED" />
    </intent-filter>
</receiver>

<service
    android:name="com.test.RunService"
    android:enabled="true" />

广播接收器

public void onReceive(Context context, Intent intent) {
    if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
        Intent serviceLauncher = new Intent(context, RunService.class);
        context.startService(serviceLauncher);
        Log.v("TEST", "Service loaded at start");
    }
}
trans by 2019-01-30T05:36:16Z

1 共1页