|
Then you should be able to add:
layoutHomeButton = findViewById(R.id.layoutHomeButton);
if (layoutHomeButton != null)
layoutHomeButton.setOnClickListener(new View.OnClickListener()...
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hello there. I have this BroadcastReciever which I register and unregister dynamically, in a BASE activity. The purpose, of this receiver, is very simple. I check if HOME button is pressed? The registration of the receiver is as follows:
ActivityBase
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mHomeWatcher = new HomeWatcher(this);
mHomeWatcher.setOnHomePressedListener(new OnHomePressedListener() {
@Override
public void onHomePressed() {
}
@Override
public void onHomeLongPressed() {
}
});
mHomeWatcher.startWatch();
}
protected void stopHomeWatcher(){
if(mHomeWatcher != null) {
mHomeWatcher.stopWatch();
mHomeWatcher.setOnHomePressedListener(null);
mHomeWatcher = null;
}
}
HomeWatcher
public class HomeWatcher {
public HomeWatcher(Context context) {
mContext = context;
mFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
}
public void setOnHomePressedListener(OnHomePressedListener listener) {
mListener = listener;
mReceiver = new InnerReceiver();
}
public void startWatch() {
if (mReceiver != null) {
mContext.registerReceiver(mReceiver, mFilter);
}
}
public void stopWatch() {
if (mReceiver != null) {
if(mContext != null)
mContext.unregisterReceiver(mReceiver);
}
}
class InnerReceiver extends BroadcastReceiver {
final String SYSTEM_DIALOG_REASON_KEY = "reason";
final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
if (reason != null) {
if(reason.trim().toLowerCase().equals("homekey")) {
}
}
}
}
}
}
As you can see, I test for various NULLs. Why do I still get this weird IllegalArgumentException ?
java.lang.IllegalArgumentException:
at android.app.LoadedApk.forgetReceiverDispatcher (LoadedApk.java:1012)
at android.app.ContextImpl.unregisterReceiver (ContextImpl.java:1360)
at android.content.ContextWrapper.unregisterReceiver (ContextWrapper.java:608)
at com.hiclass.earthlivecam.publiccam.earthcam.webcamhd.utils.HomeWatcher.stopWatch (HomeWatcher.java:39)
at com.hiclass.earthlivecam.publiccam.earthcam.webcamhd.ui.activities.ActivityBase.stopHomeWatcher (ActivityBase.java:442)
at com.hiclass.earthlivecam.publiccam.earthcam.webcamhd.ui.activities.ActivityMain.access$301 (ActivityMain.java:77)
at com.hiclass.earthlivecam.publiccam.earthcam.webcamhd.ui.activities.ActivityMain$15.onClick (ActivityMain.java:911)
at android.view.View.performClick (View.java:5703)
at android.view.View$PerformClick.run (View.java:22811)
at android.os.Handler.handleCallback (Handler.java:836)
at android.os.Handler.dispatchMessage (Handler.java:103)
at android.os.Looper.loop (Looper.java:203)
at android.app.ActivityThread.main (ActivityThread.java:6297)
|
|
|
|
|
Does the exception say that the receiver is not registered?
At a guess, you're calling unregisterReceiver twice.
I don't "do" Android dev, but I suspect you'd want something more like this:
public void setOnHomePressedListener(OnHomePressedListener listener) {
mListener = listener;
}
public void startWatch() {
if (mListener != null && mReceiver == null) {
mReceiver = new InnerReceiver();
mContext.registerReceiver(mReceiver, mFilter);
}
}
public void stopWatch() {
if (mReceiver != null) {
mContext.unregisterReceiver(mReceiver);
mReceiver = null;
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
hey forum, I'm designing an email for an email marketing campaign, and I want that when a person clicks on a button, open a page in WordPress and capture the email of the person who clicked on it to autofill a form with that email. is possible.?
in my case, it's for people to confirm that they want a free value and I would like them not to have to write their mail again.
Thanks
|
|
|
|
|
What does this have to do with Android? The Web Development forum[^] would have been the obvious place to ask this.
When you send the email, add the recipient's email address to the hyperlink as a querystring. You'll need to URL-encode it to make sure it transfers properly.
For example:
<a href="https://your-wordpress-site/some-page.ext?foo%40test.domain">Click me!</a>
When the user clicks on the link, you can then extract the value from the querystring using server-side code (or Javascript).
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
This method allows you to manually connect to Gmail's SMTP servers to send your WordPress emails. First, you need to visit Settings » WP Mail SMTP page to configure the plugin settings. You need to start by providing the Gmail address you want to use in the From email field, and your name in the name field.
|
|
|
|
|
Good work, Keep designing.
|
|
|
|
|
I have set up a client-server architecture such that my raspberry pi 3 records audio, performs some analysis on it, and then sends the data (via TCP) to the android app to display on the app screen. The recording and analysis is done and I am able to make the connection and transfer string data that displays on the app with no problem. However, I have been unsuccessful in transferring an image from rpi to android app. So basically, the image is stored on the rpi and I an attempting to transfer the image to the app to display it. I have been working on this for over a week with no luck so any help would be greatly appreciated!
My current implementation (all code provided below):
On rpi (python): Like I said, sending strings and displaying them on the android app is done without any problem. When I am sending the image portion of the audio analysis, I send a string first that says "?start" so that the android side knows that an image instead of a string is about to be sent (and will wait to update the GUI until it receives the entire image). Then, I open the image stored on rpi and read the entire image as a byte array (typically about 40-50k bytes). I get the length of the byte array and send that as a string to android app. Finally, I send the byte array to the android and it waits for an OK message from the app. All of this works without reporting any errors.
On android app (java): When the app receives the "?start" string, it then uses a Buffered Reader (which is what I used to read the string data I had transferred to the app successfully earlier) to read the size of the image byte array. Then, I create 2 buffers, msg_buff and img_buff. msg_buff will read in 1024 bytes at a time while img_buff will hold the entire byte array of the image. In the infinite while loop, I have a DataInputStream, called in, read bytes into msg_buff and returns the number of bytes read. Then, I concatenate the copied contents of msg_buff into img_buff. Once the bytes read from in is -1 or the img_offset (which is just the total number of bytes read) is greater than or equal to the size of the image bytes array, the while loop is broken. Then, I would attempt to save the image to android internal storage and then load it later to an imageView to display it. This code does successfully read in the bytes until there are around 2000-3000 bytes left to be read and then it seems to freeze on the int bytes_read = in.read(msg_buff, 0, msg_buff.length) line. I have not been able to get past that point so I do not know if saving the image to internal storage and then loading it to imageview that way will work either.
I have also tried using base64 encoding/decoding but that also kept producing errors. I have tried rpi only sending 1024 bytes of the image at a time but that also did not work. I have tried several implementations of this approach but nothing has worked so far. If anyone sees anything wrong or has another approach, I am all ears!
Android Studio (app side):
InputStream sin = socket.getInputStream();
OutputStream sout = socket.getOutputStream();
DataInputStream in = new DataInputStream(sin);
mBufferIn = new BufferedReader(new InputStreamReader(socket.getInputStream()));
while (mRun) {
mServerMessage = mBufferIn.readLine();
if (mServerMessage != null && mMessageListener != null) {
if(mServerMessage.equals("?start"))
{
int size = Integer.parseInt(mBufferIn.readLine());
byte[] msg_buff = new byte[1024];
byte[] img_buff = new byte[size];
int img_offset = 0;
while(true){
int bytes_read = in.read(msg_buff, 0, msg_buff.length);
if(bytes_read == -1){ break; }
System.arraycopy(msg_buff, 0, img_buff, img_offset, bytes_read);
img_offset += bytes_read;
if( img_offset >= size) { break; }
}
ContextWrapper cw = new ContextWrapper(ApplicationContextProvider.getContext());
File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
File mypath = new File(directory, "signal.jpeg");
Bitmap bitmap = BitmapFactory.decodeByteArray(img_buff, 0, img_buff.length);
FileOutputStream fos = null;
try{
fos = new FileOutputStream(mypath);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
byte[] OK = new byte[] {0x4F, 0x4B};
sout.write(OK);
} catch (Exception e) {
e.printStackTrace();
}
Raspberry Pi (python):
def image_to_byte_array(image_file, conn):
with open(image_file, 'rb') as imageFile:
content = imageFile.read()
conn.sendall("?start\n".encode('utf-8'))
size = len(content)
strSize = str(size) + "\n"
conn.sendall(strSize.encode('utf-8'))
conn.sendall(content)
Note that conn is the connection between the app and the rpi and the images are PNG.
If anyone knows why this isn't working or has a better way for me to do this, I would greatly appreciate it!! Thank you in advance!! :)
|
|
|
|
|
Your problem description (which is very clear, thank you), and code all seems correct. The way you are handling the data between the two endpoints should do what you want. When the program freezes on the in.read , it usually means that the network layer is waiting for a packet to be received. You could try setting a timeout value so the read does not block forever. This will at least let you check how much data is still not received: Socket.setSoTimeout(int) (Java Platform SE 7 )[^]
|
|
|
|
|
i need complete code of a search engine where it crawl minimum of 5 sites and must also allow a user to enter a term and get its url
|
|
|
|
|
|
Google might help you—not kidding, they usually do release some guidance on how they work on the crawlers, indexers etc.
If that is not what you are looking for, then try to study Elasticsearch and see how it works; GitHub - elastic/elasticsearch: Open Source, Distributed, RESTful Search Engine. But remember, before reading the source code, it might need that you study the basics of how coding works as well as the core components of computer science, as search engines or indexation gets pretty messy down the road.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
hello, am looking for a simple code in C# to develop QR scanner for android phone camera. please help.
|
|
|
|
|
|
hi
i have android webview app. one of my parts is to download blob sound data link to my device.my step as flow:
1- live audio record
2- create blob url
3- i can listen the url, and once press download i receive this message (unknown blob protocol)
any solution please?
|
|
|
|
|
Member 14501743 wrote: ...i receive this message (unknown blob protocol) From where? What does the download code look like? Have you stepped through it using the debugger?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
my html script is :
تسجيل الصوت
الايعازات
بدء
ايقاف
-->
and my js script is :
'use strict'
var log = console.log.bind(console),
id = val => document.getElementById(val),
ul = id('ul'),
gUMbtn = id('gUMbtn'),
start = id('start'),
stop = id('stop'),
stream,
recorder,
counter = 1,
chunks,
media;
gUMbtn.onclick = e => {
var mv = id('mediaVideo'),
mediaOptions = {
audio: {
tag: 'audio',
type: 'audio/mpeg',
ext: '.mp3',
gUM: { audio: true }
}
};
media = mv.checked ? mediaOptions.video : mediaOptions.audio;
navigator.mediaDevices.getUserMedia(media.gUM).then(_stream => {
stream = _stream;
id('gUMArea').style.display = 'none';
id('btns').style.display = 'inherit';
start.removeAttribute('disabled');
recorder = new MediaRecorder(stream);
recorder.ondataavailable = e => {
chunks.push(e.data);
if (recorder.state == 'inactive') makeLink();
};
log('got media successfully');
}).catch(log);
}
start.onclick = e => {
start.disabled = true;
stop.removeAttribute('disabled');
chunks = [];
recorder.start();
}
stop.onclick = e => {
stop.disabled = true;
recorder.stop();
start.removeAttribute('disabled');
}
function makeLink() {
var blob = new Blob(chunks, { type: media.type })
, url = window.URL.createObjectURL(blob)
, li = document.createElement('li')
, mt = document.createElement(media.tag)
, hf = document.createElement('a')
;
mt.controls = true;
mt.src = url;
hf.href = url;
hf.download = `SRV_${counter++}${media.ext}`;
hf.innerHTML = `donwload ${hf.download}`;
li.appendChild(mt);
li.appendChild(hf);
ul.appendChild(li);
}
|
|
|
|
|
Hello to all! Hope you are fine. I am developing an e-commerce android app and integrating Stripe payment gateway in it and using Google Fire base as real time database.
I browsed the official website of stripe and took the source code from there. I used my test key from there. I successfully generated Stripe Token and saved it on my server (i-e Fire base). But I am unable to make an actual charge by using that token. That means no transaction shows on my stripe account. I am pasting my code, guide me what should i do to create/make charge?
Card cardToSave = cardInputWidget.getCard();
if (cardToSave == null) {
Toast.makeText(getActivity(),"Invalid Card Data",Toast.LENGTH_LONG).show();
// mErrorDialogHandler.showError("Invalid Card Data");
}
else{
Stripe stripe = new Stripe(MainActivity.mcont,
"pk_test_XZFc6CW7wmDMl4WWESxtvWd300ibs1wr85");
stripe.createToken(
cardToSave,
new TokenCallback() {
public void onSuccess(final Token token) {
// Send token to your server
customer_ref =
database.getReference("Customers").child(MainActivity.user.getUid());
final String tokenid = token.getId();
//saving the tokenID on my server(i-e fiebase)
final Map<String, Object> params = new HashMap<>();
params.put("amount", paid);
params.put("currency", "usd");
params.put("description", "Example charge");
params.put("source", tokenid);
HashMap map = new HashMap();
map.put("StripeToken",tokenid);
customer_ref.updateChildren(map);
try {
// creating charge object
Charge charge = Charge.create(params);
} catch (AuthenticationException e) {
e.printStackTrace();
} catch (InvalidRequestException e) {
e.printStackTrace();
} catch (APIConnectionException e) {
e.printStackTrace();
} catch (CardException e) {
e.printStackTrace();
} catch (APIException e) {
e.printStackTrace();
}
|
|
|
|
|
The Stripe developers hang out here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
--Android Code
--============
<pre>private class UploadData extends AsyncTask<String, Void, String>
{
@Override
protected void onPreExecute()
{
progressDialog.setMessage("Wait !!! Transferring SQLite Data into SQL Server DB.");
progressDialog.setIndeterminate(false);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setCancelable(false);
progressDialog.show();
}
@Override
protected void onPostExecute(String result)
{
progressDialog.dismiss();
AlertDialog YesNo1 = DialogYesNo();
YesNo1.setMessage("Hh Count Tablet: " + HhTablet + " , Hh Count Server: " + HhServer + "\n" + " -- has been transferred to SQL server DB !!! ");
YesNo1.setCancelable(false);
YesNo1.show();
HhServer = 0;
}
@Override
protected String doInBackground(String... params)
{
String result = "";
httpclient = new DefaultHttpClient();
httppost = new HttpPost("http://172.16.15.13/testing/datasync.php");
try
{
try
{
cursor = ConnectionDB.SelectRecord("Select HH,PartM,GISID,Mohalla from HH");
HhTablet = cursor.getCount();
if (cursor != null)
{
cursor.moveToFirst();
while (!cursor.isAfterLast())
{
for (int k = 0; k < HhTablet; k++)
{
nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("HH", cursor.getString(cursor.getColumnIndex("HH"))));
nameValuePairs.add(new BasicNameValuePair("PartM", cursor.getString(cursor.getColumnIndex("PartM"))));
nameValuePairs.add(new BasicNameValuePair("GISID", cursor.getString(cursor.getColumnIndex("GISID"))));
nameValuePairs.add(new BasicNameValuePair("Mohalla", cursor.getString(cursor.getColumnIndex("Mohalla"))));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HhServer = HhServer + 1;
}
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpclient.execute(httppost, responseHandler);
JSONObject json = new JSONObject(responseBody);
JSONArray jArray = json.getJSONArray("posts");
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < jArray.length(); i++)
{
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = jArray.getJSONObject(i);
String s = e.getString("post");
JSONObject jObject = new JSONObject(s);
map.put("HH", jObject.getString(cursor.getString(cursor.getColumnIndex("HH"))));
map.put("PartM", jObject.getString(cursor.getString(cursor.getColumnIndex("PartM"))));
map.put("GISID", jObject.getString(cursor.getString(cursor.getColumnIndex("GISID"))));
map.put("Mohalla", jObject.getString(cursor.getString(cursor.getColumnIndex("Mohalla"))));
mylist.add(map);
cursor.moveToNext();
}
}
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
finally
{
cursor.close();
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
return result;
}
}
--PHP code
--==========
<?php
include ("dbconnection.php");
$json = file_get_contents('php://input');
$obj = json_decode($json);
$HH=$_POST[HH];
$PartM=$_POST[PartM];
$GISID=$_POST[GISID];
$Mohalla=$_POST[Mohalla];
$query = "INSERT INTO HH(HH,PartM,GISID,Mohalla) VALUES ('$HH','$PartM','$GISID','$Mohalla')";
$stmt = $conn->query( $query );
if ($query)
{
$response["success"] = 1;
$response["message"] = "Record is successfully created.";
echo json_encode($response);
}
else
{
$response["success"] = 0;
$response["message"] = "Sorry! An error occurred.";
echo json_encode($response);
}
$posts = array(1);
header('Content-type: application/json');
echo json_encode(array('posts'=>$posts));
$stmt = null;
$conn = null;
?>
modified 6-May-19 6:12am.
|
|
|
|
|
What exactly happens when you run this code? What is the data sent in the URL, and what is the response from the server?
|
|
|
|
|
Data is sending properly from this code but I am having problem in the loop. In my SQLite DB I am having 5 records but I am getting only one record when I am sending from the TAB.
|
|
|
|
|
Sorry but your descrikption is not clear. Please edit your question and explain exactly where the problem occurs, and what happens.
|
|
|
|
|
|
So I have created my first mobile app with xamarin cross platform. I only use the Android part.
I have tested my app extensively and all works very fine.
I also have a server and all the data comes from this server by APIs.
All the CRUD is working
After that I created an apk-file and send it to my tablet and Phone.
The pages/View are presented but with a very small font.
But that's not my problem. The problem is: no data. It looks like nothing is returned but, there are also no messages of network problems.
So, what's going on?
|
|
|
|
|