Detecting new MMS (Android 2.1) - android

I'd like to recognize arrival of new MMS msg (after it is downloaded to inbox). I am doing the following:
private MMSContentObserver mMmsCO;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
h = new Handler();
mMmsCO = new MMSContentObserver(h);
getContentResolver().registerContentObserver (Uri.parse("content://mms"), true, mMmsCO);
}
where
private class MMSContentObserver extends ContentObserver {
public MMSContentObserver(Handler h) {
super(h);
}
#Override
public boolean deliverSelfNotifications() {
return false;
}
#Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
}
}
However, onChange is not getting called. What am I missing?
Thanks in advance.

The MMS content provider isn't part of the SDK but it can be used... a real answer here would be nice since all messaging apps use content://mms in some way or shape.
Since google decided not to standardize MMS we are all have to test on every phone out there but we still need to be able to handle MMSs in our apps.

Related

zxing qr code scanner camera showing white screen

Good day! i'm having an issue with the qr code scanner in android marshmallow and nougat using the library that i have added as dependency in my project the camera shows white screen. Code runs perfectly in lollipop and kitkat. Please let me know if there was something i have missed or something i will do to make it work. I have paste my snippets of code down below. It is my pleasure if you give me some time to notice my concern. I have seen similar topic of my issue but it did not help me work out or i have implemented it wrong. Thank you in advance.
I have zxing jar library for generating qr code, and i used me.dm7.barcodescanner:zxing:1.8.4 for scanning qr codes:
dependency {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/zxing-2.1.jar')
compile('me.dm7.barcodescanner:zxing:1.8.4'){
exclude group: 'com.google.zxing'
}
}
The Activity for the opening of the camera:
public class ScanQRCodeActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler {
private String strDataEncrypted;
private ZXingScannerView mScannerView;
public static String strEncrypt;
public static String strEncrypted;
public static String strIV;
public static boolean isScanSuccess = false;
#Override
public void onCreate(Bundle state) {
super.onCreate(state);
mScannerView = new ZXingScannerView(this);
setContentView(mScannerView);
}
#Override
public void onResume() {
super.onResume();
mScannerView.setResultHandler(this);
mScannerView.startCamera();
}
#Override
public void onPause() {
super.onPause();
mScannerView.stopCamera();
}
#Override
public void handleResult(Result result) {
strDataEncrypted = result.getText();
Log.wtf("handleResult", strDataEncrypted);
String[] strSplit = strDataEncrypted.split("\\|\\|");
strEncrypted = strSplit[0].trim();
strIV = strSplit[1];
CryptLibHelper cryptLibHelper = new CryptLibHelper();
cryptLibHelper.decrypt(strEncrypted, strIV, new CryptLibHelper.CryptLibDecryptCallback() {
#Override
public void onDecryptFailed(String str_message) {
Log.wtf("onDecryptFailed", str_message);
}
#Override
public void onDecryptSuccess(String str_message) {
if (str_message.contains("}")) {
strEncrypt = str_message.replace("}", "");
Log.wtf("onDecryptSuccess", strEncrypt);
}
}
});
onBackPressed();
isScanSuccess = true;
mScannerView.resumeCameraPreview(this);
}
}
Have you added CAMERA permission check in your app?? Since from marshmallow onwards you need to ask user for some permissions.
You can first try to manually give permission to your app from device settings.
I was experiencing this issue on and off, my problem was that my application was requesting camera permissions too late! Make sure your application is requesting the camera permissions BEFORE an instance of ZXing qr scanner is created.

Unable to both start and discover a specific service with Wifi Direct

I'm pretty new with Android programming. But I have been working on this for over a week now, and it starts to get booooring.
My idea is that I want to connect two devices using Wifi Direct. But I only want to connect to those which are running my application. Besides, I want the users to be able to see some information of the other devices (such as user name), not just the MAC or the Android_XXXX name included in the WifiP2pDevice. That's why I decided that a device looking for other devices, should both start the application service and search for peers which are also broadcasting this service.
The problem (I'm testing with two real devices) is that, even though they are running exactly the same code, only one of them is getting the service discovery callbacks (the onDnsSd... listeners below). So, one side acts in the proper way, but not the other. Moreover I'm getting "old" services, meaning that apparently each time I start de service (even though I cancel previously started services), that service seems to be still broadcast during at least some minutes.
I include a shortened version of my code:
public class MoveFlufietsDialogFragment extends DialogFragment implements ChannelListener, DeviceActionListener {
public final HashMap<String, FlufietsPeer> mBuddies = new HashMap<String, FlufietsPeer>();
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
...
mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
mManager = (WifiP2pManager) getActivity().getSystemService(Context.WIFI_P2P_SERVICE);
mChannel = mManager.initialize(getActivity(), getActivity().getMainLooper(), null);
...
startRegistration();
discoverFlufietsService();
...
}
public void discoverFlufietsService() {
DnsSdTxtRecordListener txtListener = new DnsSdTxtRecordListener() {
#Override
public void onDnsSdTxtRecordAvailable(String fullDomain, Map record, WifiP2pDevice device) {
// This and the next listener are only called in one of the devices.
String serviceName = (String) record.get("serviceName");
if ((serviceName != null) && (serviceName.equals("flufiets")) {
// I put the record data in the mBuddies HashMap.
...
mBuddies.put(device.deviceAddress, myPeerDataStructure);
}
}
};
DnsSdServiceResponseListener servListener = new DnsSdServiceResponseListener() {
#Override
public void onDnsSdServiceAvailable(String instanceName, String registrationType, WifiP2pDevice resourceType) {
if (mBuddies.containsKey(resourceType.deviceAddress)) {
FlufietsPeer flufietsPeer = mBuddies.get(resourceType.deviceAddress);
WiFiPeerListAdapter adapter = ((WiFiPeerListAdapter) mFragmentList.getListAdapter());
adapter.add(flufietsPeer);
adapter.notifyDataSetChanged();
}
}
};
mManager.setDnsSdResponseListeners(mChannel, servListener, txtListener);
WifiP2pDnsSdServiceRequest serviceRequest = WifiP2pDnsSdServiceRequest.newInstance();
mManager.addServiceRequest(mChannel, serviceRequest, new ActionListener() {
// onSuccess/onFailure toasts.
});
mManager.discoverServices(mChannel, new WifiP2pManager.ActionListener() {
// onSuccess/onFailure toasts.
});
}
public void startRegistration() {
mManager.clearLocalServices(mChannel, new ActionListener() {
// onSuccess/onFailure toasts.
});
Map record = new HashMap();
record.put("serviceName", "flufiets");
...
WifiP2pDnsSdServiceInfo serviceInfo = WifiP2pDnsSdServiceInfo.newInstance(flufietsService, "_tcp", record);
mManager.addLocalService(mChannel, serviceInfo, new ActionListener() {
// onSuccess/onFailure toasts.
});
}
#Override
public void onResume() {
super.onResume();
mReceiver = new WiFiDirectBroadcastReceiver(mManager, mChannel, this);
getActivity().registerReceiver(mReceiver, mIntentFilter);
}
#Override
public void onPause() {
super.onPause();
getActivity().unregisterReceiver(mReceiver);
}
#Override
public void onStop() {
super.onStop();
mManager.clearLocalServices(mChannel, new ActionListener() {
// onSuccess/onFailure toasts.
});
}
...
}
The problem doesn't seem to be related with the device itself (sometimes it works, sometimes it doesn't, but always only in one of them). I suspect it has to do with either trying to discover a service that we ourselves are broadcasting, or having the same service being offered by two devices. I have tried changing the names of the service, so each device would offer either a "send" or "receive" service, but it doesn't work. I only get the callbacks called (onDnsSd...) in one of the devices.
And that thing about getting old services, when I always clear them, is weird (I do include a timestamp in the service record data, and I could always discard all but the last, but doesn't seem to be logical).
Any ideas? ANY help would be VERY appreciated, because writing the application is not funny any more (:-)=
Thanks a lot!
You need to wait until the clearLocalService call succeeds before adding the local service later. So put the addLocalService call into the onSuccess callback of the clearLocalServices.

connect iPhone to Android's Wifi Direct soft AP

I know that Wifi Direct works by creating a Soft AP (software access point) in one of the devices. I also know that many Androids support Wifi Direct, but iPhones do not.
My question is: is it possible to create a device-to-device wifi link that is Wifi Direct on the Android side, but regular wifi on the iPhone side? Where the Android's Wifi Direct would be presenting a soft AP, which the iPhone would see as indistinguishable from a regular AP and be able to associate to.
Imagine that this is out in the wilderness where no router AP is available. Also, neither user has a tethering plan.
This link would be used by a Bump-like app to transfer files.
Depending on your phone you can just set up your Android phone as a portable hotspot and connect to that with the iPhone. From there it would be application specific to get data transferred.
However you can also use the Androids WiFi-Direct libraries. In that case you would use them to set up the Android phone to create a "Group owner", which basically is the same as it being a portable hotspot. Check out:
http://developer.android.com/guide/topics/connectivity/wifip2p.html
I'll give you a code example to help you get started.
public class WifiDirectAPtestActivity extends Activity
{
private WifiP2pManager manager;
private boolean isWifiP2pEnabled = false;
private boolean retryChannel = false;
private final IntentFilter intentFilter = new IntentFilter();
private Channel channel;
private BroadcastReceiver receiver = null;
public void setIsWifiP2pEnabled(boolean isWifiP2pEnabled) {
this.isWifiP2pEnabled = isWifiP2pEnabled;
}
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// add necessary intent values to be matched.
intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
channel = manager.initialize(this, getMainLooper(), null);
}
/** register the BroadcastReceiver with the intent values to be matched */
#Override
public void onResume() {
super.onResume();
receiver = new WiFiDirectBroadcastReceiver(manager, channel, this);
registerReceiver(receiver, intentFilter);
createGroup();
}
#Override
public void onPause() {
super.onPause();
unregisterReceiver(receiver);
manager.removeGroup(channel, new ActionListener() {
#Override
public void onFailure(int reasonCode) {
Log.d("WifiDirectAptestActivity", "Disconnect failed. Reason :" + reasonCode);
}
#Override
public void onSuccess() {
Log.d("WifiDirectAptestActivity", "Should have been sucessfully removed");
}
});
}
public void createGroup()
{
manager.createGroup(channel, new ActionListener() {
#Override
public void onSuccess() {
// WiFiDirectBroadcastReceiver will notify us. Ignore for now.
Log.d("WifiDirectAPtestActivity", "Group creating request successfully send");
}
#Override
public void onFailure(int reason) {
Toast.makeText(WifiDirectAPtestActivity.this, "Connect failed. Retry.",
Toast.LENGTH_SHORT).show();
}
});
}
In addition you'll need the broadcast receiver, look at the WiFi-Direct demo and it should be clear to you.
Note that line manager.createGroup(channel, new ActionListener() is the codeline of interest, it is this line that actually sets up the device as a portable hotspot.
Hope this clarifies things, I don't really know how detailed explanation you need. Comment if some things are not clear.

ContentObserver doesn't work for Browser Bookmarks on Nexus 7?

I register a ContentObserver to monitor Bookmarks changes of Chrome on Nexus 7, but there is not any callback get from onChange().
With the same code, I can get ContentObserver callback of Android default browser on other devices.
Does Chrome not support ContentObserver callback on Nexus 7?
Code as below:
getApplication().getContentResolver().registerContentObserver(Browser.BOOKMARKS_URI, true, observer);
...
static class HistoryOberser extends ContentObserver {
public HistoryOberser() {
super(null);
}
#Override
public boolean deliverSelfNotifications() {
return true;
}
#Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Log.d(TAG, "onChange: " + selfChange);
}
}
Use URI "content://com.android.chrome.browser/bookmarks" for Android Crhome browser bookmarks can make the observer works.

How to get email received event in Android

I could not find a way to listen email received event. Can any one please suggest me on this.
your valuable suggestions are highly appreciated.
The answer is no. 3rd party apps can't access the stock Email applications data.
I could succeed upto an extent, Now I could receive events for any changes happening in gmail account but still i am not clear about how to find only incoming mails.
Note:
I got some hacking techniques for getting this done but it will not work starting from froyo release.
currently I am using below code:
onChange method will get invoked for any changes happening in gmail.
mContext.getContentResolver().registerContentObserver(Uri.parse("content://gmail-ls/unread"), false, GmailObserver(new Handler() {}));
class GmailObserver extends ContentObserver {
public GmailObserver(Handler handler) {
super(handler);
}
#Override
public boolean deliverSelfNotifications() {
System.out.println("### ContentObserver deliverSelfNotifications");
return super.deliverSelfNotifications();
}
#Override
public void onChange(boolean selfChange) {
System.out.println("### ContentObserver onChange");
super.onChange(selfChange);
}
}

Categories

Resources