[HELP][NEWBIE]Camera Activity Not working... - Java for Android App Development

Hi people, I am newbie , trying to learn android developing.
So i was making this app. which uses the camera client android clicks a picture and then sets it as wallpaper, as per the user's request.
But when i try to install it on my phone (Samsung Galaxy y duos ). It says application not installed. I am not able to understand why. I have also added the permissions on the Android manifest. Please do help me out. I will be attaching the xml for the camera app and its Class.
THE JAVA CLASS...
Code:
package com.example.done;
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
public class Camera extends Activity implements View.OnClickListener {
Button camera;
ImageButton done;
ImageView wallpaper;
int cameraData = 0;
Intent i;
Bitmap pic;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.photo);
intial();
camera.setOnClickListener(this);
done.setOnClickListener(this);
InputStream is = getResources().openRawResource(R.drawable.abc);
pic= BitmapFactory.decodeStream(is);
int cameraData = 0;
Intent i;
}
private void intial() {
// TODO Auto-generated method stub
camera = (Button) findViewById(R.id.camera);
done = (ImageButton) findViewById(R.id.imgTile);
wallpaper = (ImageView) findViewById(R.id.imagButt);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.camera:
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, cameraData);
break;
case R.id.imagButt:
try {
getApplicationContext().setWallpaper(pic);
} catch (IOException e) {
e.printStackTrace();
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
Bundle e = i.getExtras();
pic = (Bitmap) e.get("data");
wallpaper.setImageBitmap(pic);
}
}
}[/CODE]
the Xml file (photo.xml)
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="xda wont allow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imgTile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/abc"
android:layout_gravity="center" />
<ImageButton
android:id="@+id/imagButt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/ic_launcher" />
<Button
android:id="@+id/camera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Button" />
</LinearLayout>
ThankYou in advance

Please add your manifest to the OP too, the issue is most likely in it (The first thing that comes to my mind is that your app has a higher android:minSdkVersion than your device's version of android)
Also, did you export a signed apk?
Are you using Eclipse ?
If you do, just make a right click on your project name and choose "Run As --> Android Application" to launch it on your connected device with adb enabled.
If you want to export a signed apk, right click your project's name and choose "Android tools --> Export Signed Application Package..." and follow the instructions in the daemon.

Manifest
Androguide.fr said:
Please add your manifest to the OP too, the issue is most likely in it (The first thing that comes to my mind is that your app has a higher android:minSdkVersion than your device's version of android)
Also, did you export a signed apk?
Are you using Eclipse ?
If you do, just make a right click on your project name and choose "Run As --> Android Application" to launch it on your connected device with adb enabled.
If you want to export a signed apk, right click your project's name and choose "Android tools --> Export Signed Application Package..." and follow the instructions in the daemon.
Click to expand...
Click to collapse
Yeah i am on eclipse.
And yup I am using a signed APK.
Actually, if i hit run. It would start up my emulator(It is installng on that perfectly).
But i have not connected my emulator to the webcam, so it would forceClose.
I have also set my emulator to Qvga.
And yup, the i have attached the manifest too.:good::good:

Manifest
Androguide.fr said:
Please add your manifest to the OP too, the issue is most likely in it (The first thing that comes to my mind is that your app has a higher android:minSdkVersion than your device's version of android)
Also, did you export a signed apk?
Are you using Eclipse ?
If you do, just make a right click on your project name and choose "Run As --> Android Application" to launch it on your connected device with adb enabled.
If you want to export a signed apk, right click your project's name and choose "Android tools --> Export Signed Application Package..." and follow the instructions in the daemon.
Click to expand...
Click to collapse
Yeah i am on eclipse.
And yup I am using a signed APK.
Actually, if i hit run. It would start up my emulator(It is installng on that perfectly).
But i have not connected my emulator to the webcam, so it would forceClose.
I have also set my emulator to Qvga.
And yup, the i have attached the manifest too.:good::good:
Actually the app i am developing, includes a menu which includes some other apps. Everything other app was working fine, until i added the camera app. . If you want the classes of the other apps, I can provide you that. But please help me. Thanks
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.done"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Splash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.done.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.done.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.done.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Password"
android:label="@string/app_name" >
</activity>
<activity
android:name=".Email"
android:label="@string/app_name" >
</activity>
<activity
android:name=".Camera"
android:label="cameraApp"
android:screenOrientation="portrait" >
</activity>
</application>
</manifest>

Add this permission to your manifest :
Code:
<uses-permission android:name="android.permission.CAMERA"/>
What version of Android is your device running ? You might wanna change this line
Code:
android:targetSdkVersion="8"
to :
Code:
android:targetSdkVersion="17"
if you want your app to support devices running ics & jellybean and/or be able to use the latest APIs (download the android 4.2.2 sdk platform if eclipse throws an error)
EDIT : you also have a whitespace in this line, remove it :
Code:
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CA [COLOR="DarkRed"]here [/COLOR]PTURE

It would be helpful if you paste in here the output of the console. It has nothing to do with the java code since it is being installed in the emulator.

Still not working
Androguide.fr said:
Add this permission to your manifest :
Code:
<uses-permission android:name="android.permission.CAMERA"/>
What version of Android is your device running ? You might wanna change this line
Code:
android:targetSdkVersion="8"
to :
Code:
android:targetSdkVersion="17"
if you want your app to support devices running ics & jellybean and/or be able to use the latest APIs (download the android 4.2.2 sdk platform if eclipse throws an error)
EDIT : you also have a whitespace in this line, remove it :
Code:
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CA [COLOR="DarkRed"]here [/COLOR]PTURE
Click to expand...
Click to collapse
As you said, i made all the changes. (Includind premissions etc.)
But it is not working.
When i run it on my emulator, it is getting installed. But when i run it on my phone.. It says app not installed.
Also I am attchiing the console output.
[2013-04-16 12:49:11 - Emulator] emulator: WARNING: Could not initialize OpenglES emulation, using software renderer.
[2013-04-16 12:49:12 - done] New emulator found: emulator-5554
[2013-04-16 12:49:12 - done] Waiting for HOME ('android.process.acore') to be launched...
[2013-04-16 12:50:09 - done] HOME is up on device 'emulator-5554'
[2013-04-16 12:50:09 - done] Uploading done.apk onto device 'emulator-5554'
[2013-04-16 12:50:35 - done] Installing done.apk...
[2013-04-16 12:50:57 - done] Success!
[2013-04-16 12:50:57 - done] Starting activity com.example.done.Splash on device emulator-5554
[2013-04-16 12:51:00 - done] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.done/.Splash }

hiphop12ism said:
As you said, i made all the changes. (Includind premissions etc.)
But it is not working.
When i run it on my emulator, it is getting installed. But when i run it on my phone.. It says app not installed.
Also I am attchiing the console output.
[2013-04-16 12:49:11 - Emulator] emulator: WARNING: Could not initialize OpenglES emulation, using software renderer.
[2013-04-16 12:49:12 - done] New emulator found: emulator-5554
[2013-04-16 12:49:12 - done] Waiting for HOME ('android.process.acore') to be launched...
[2013-04-16 12:50:09 - done] HOME is up on device 'emulator-5554'
[2013-04-16 12:50:09 - done] Uploading done.apk onto device 'emulator-5554'
[2013-04-16 12:50:35 - done] Installing done.apk...
[2013-04-16 12:50:57 - done] Success!
[2013-04-16 12:50:57 - done] Starting activity com.example.done.Splash on device emulator-5554
[2013-04-16 12:51:00 - done] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.done/.Splash }
Click to expand...
Click to collapse
You're giving us the output for the emulator here... We need to see the output for when you install it on an actual device as it's where your problem is.

I attached a screenshot.
I hope that helps.
So as i told you, everything was working fine. Until i added the camera app. But for experiment's sake, i deleted the app's xml, java and the activity from the manifest. But still the same result.
As i.told you, the camera app is a sub app in my phone..
The whole app contains some more app. But even then its not working:thumbup::thumbup:
Sent from my GT-S6102 using xda app-developers app

Problem Solved
Hey fellas.
I thought that changing the phone, would solve the problem,
So i used samsung s2 instead of samasing galaxy y duos.
And the app worked....
But i am not able to determine the reason.

Why don't you post the output of the console? You have been asked several times :good:

You will not find anything in the console.
As eclipse installes the apk in my emulator. In the emulator, it installs perfectly. So everything in the console is positve. Anyways i have already attached the console output in the previous page. And if you need the logcat. I will provide you.
Anyways, a great thanks for your concern
--------+---------+-----------+-------------
Sent from my GT-S6102 using xda app-developers app

Could you provide us your android manifest?
Maybe you need to set a lower minSdkVersion. (Although it says "Parsing error" on my Samsung Galaxy Ace if there is a wrong minSdkVersion)

I have copied the manifest in the previous page. I have tried putting minsdk on qvga adpi.
But it didnt work..
Sent from my GT-S6102 using xda app-developers app

hiphop12ism said:
I have copied the manifest in the previous page. I have tried putting minsdk on qvga adpi.
But it didnt work..
Sent from my GT-S6102 using xda app-developers app
Click to expand...
Click to collapse
Ah. Ok. Thanks.
The minSdkVersion is the minimum Android version which has to be installed on the device.
8 is the code for Android 2.2.
Which Android version is running on your device? Maybe you will need to set it to a lower value.

i have 2.3.6
Sent from my GT-S6102 using xda app-developers app

Related

when i tried to run my app via eclipse !!!!!!!

when i tried to run my app on HTC deesire using eclipse the message pops up ::::::
[2013-06-20 01:27:42 - IcsAsDef] Failed to install IcsAsDef.apk on device 'HT04GPL02764!
[2013-06-20 01:27:42 - IcsAsDef] (null)
[2013-06-20 01:27:42 - IcsAsDef] Launch canceled!
Please provide us more information.
Did you enable the USB debugging?
Hello
I will try to solve this problem as soon as, Thanks for posting. I would like to solve this. Good day.
nikwen said:
Please provide us more information.
Did you enable the USB debugging?
Click to expand...
Click to collapse
i have enabled it about year ago ......... when i rebooted the phone it works ... but
look i am a newbie in app creating
i am learning it now from this site http://developer.android.com/training/basics/firstapp/starting-activity.html
but when i run this step after learning it ... its just like the before
if u entered the site you will see ... that if u typed a message and pressed the formed bottom (send)
the message will be desplayed in the whole app screen
but when i run it .. and pressed the bottom it reamains as it is
sorry for my bad english .. but please be patient with me :good: :good:
ahmed_alaa said:
when i tried to run my app on HTC deesire using eclipse the message pops up ::::::
[2013-06-20 01:27:42 - IcsAsDef] Failed to install IcsAsDef.apk on device 'HT04GPL02764!
[2013-06-20 01:27:42 - IcsAsDef] (null)
[2013-06-20 01:27:42 - IcsAsDef] Launch canceled!
Click to expand...
Click to collapse
Try this:
Open a command prompt window and type 'adb kill-server' (Without quotation marks). When it's done, type 'adb start-server'
If that doesn't work, try restarting eclipse, your computer and your device. I've had this problem before, and usually one of these steps solves it.
ahmed_alaa said:
i have enabled it about year ago ......... when i rebooted the phone it works ... but
look i am a newbie in app creating
i am learning it now from this site http://developer.android.com/training/basics/firstapp/starting-activity.html
but when i run this step after learning it ... its just like the before
if u entered the site you will see ... that if u typed a message and pressed the formed bottom (send)
the message will be desplayed in the whole app screen
but when i run it .. and pressed the bottom it reamains as it is
sorry for my bad english .. but please be patient with me :good: :good:
Click to expand...
Click to collapse
So there is a second problem, too?! Please post your complete code. It could be that you missed one line.
no the first proplem has been solved when i rebooted the device
nikwen said:
So there is a second problem, too?! Please post your complete code. It could be that you missed one line.
Click to expand...
Click to collapse
no the first proplem has been solved when i rebooted the device ............ and thanks for help any way... i am talking now about the new one that in the second lesson i learned in the page that i have been shared it .... no thing happen when i press the (send) button i created its just like the first lesson (creating button without any respond to click ) .......... so which section of codes you need me to post it !!!!!
ahmed_alaa said:
no the first proplem has been solved when i rebooted the device ............ and thanks for help any way... i am talking now about the new one that in the second lesson i learned in the page that i have been shared it .... no thing happen when i press the (send) button i created its just like the first lesson (creating button without any respond to click ) .......... so which section of codes you need me to post it !!!!!
Click to expand...
Click to collapse
Please post your xml layouts and your two Activities.
ok
nikwen said:
Please post your xml layouts and your two Activities.
Click to expand...
Click to collapse
the activity_main.xml
?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
androidrientation="horizontal">
<EditText android:id="@+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
androidnClick="sendMessage" />
</LinearLayout>
activity_display_message
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
androidaddingBottom="@dimen/activity_vertical_margin"
androidaddingLeft="@dimen/activity_horizontal_margin"
androidaddingRight="@dimen/activity_horizontal_margin"
androidaddingTop="@dimen/activity_vertical_margin"
tools:context=".DisplayMessageActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
thnx for your caring am just a noob in creating apps ... and i wish to be better with your assist
ahmed_alaa said:
the activity_main.xml
?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
androidrientation="horizontal">
<EditText android:id="@+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
androidnClick="sendMessage" />
</LinearLayout>
activity_display_message
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
androidaddingBottom="@dimen/activity_vertical_margin"
androidaddingLeft="@dimen/activity_horizontal_margin"
androidaddingRight="@dimen/activity_horizontal_margin"
androidaddingTop="@dimen/activity_vertical_margin"
tools:context=".DisplayMessageActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
thnx for your caring am just a noob in creating apps ... and i wish to be better with your assist
Click to expand...
Click to collapse
oh i am sorry for that emotions all the is : D AND ALL THE is : P i think you know that
others...
ahmed_alaa said:
oh i am sorry for that emotions all the is : D AND ALL THE is : P i think you know that
Click to expand...
Click to collapse
DisplayMessageActivity.java
package com.example.icsasdef;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class DisplayMessageActivity extends Activity {
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView);
}
}
MainActivity.java
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.content.Intent;
import android.widget.EditText;
public class MainActivity extends Activity {
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
// Do something in response to button
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
}
}
oh i found the missed line
ahmed_alaa said:
oh i am sorry for that emotions all the is : D AND ALL THE is : P i think you know that
Click to expand...
Click to collapse
the missed line was here
in MainActivity.java
i missed that line
startActivity(intent);
ty so much that you noticed me to search about the missed line .........

How make application with maps? (apiKey)

Hi, I am new in xda-developers forum. I have written my first simple application which uses GPS. Now I want to use Google Maps. Is problem because it want apiKey. My apiKey is in Google Code Api's Console. There is Android apps:
8A5:....:72:88:AE;com.borneq.heregpslocation and ApiKey : AIzaSyCh0XWRIXaTizxYcnWO8K7eFLZEysfGJvM (it is public or private?)
I modified three file to do with maps:
* AndroidManifest.xml:
Code:
<permission
android:name="com.borneq.heregpslocation.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.borneq.heregpslocation.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Code:
<uses-library android:name="com.google.android.maps" />
Code:
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCh0XWRIXaTizxYcnWO8K7eFLZEysfGJvM" />
Second file is activity_main.xml :
Code:
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="AIzaSyCh0XWRIXaTizxYcnWO8K7eFLZEysfGJvM"
android:clickable="true" />
Third is .MainActivity.java :
import com.google.android.maps.MapActivity;
public class MainActivity extends MapActivity implements OnClickListener {
Click to expand...
Click to collapse
Previously used controls I commnted
Project compiles but application breaks at start. I attach source: zipped program and logCat
Thanks!
The app crashs in line 77 of MainActivity. It's a NullPointerException.
Code:
boolean isGps = locationManager.isProviderEnabled("gps");
The reason for the crash is that in onCreate you commented this line out:
Code:
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Due to this the variable locationManager is null and it crashes later because it cannot handle a null value. Just uncomment the line from onCreate which I pasted above. That's it.
How did I know that? It's in the logcat:
Code:
Caused by: java.lang.[B]NullPointerException[/B]
at com.borneq.heregpslocation.MainActivity.setButtonState([B]MainActivity.java:77[/B])
This guide might help you understand logcats (focus on that part of the guide): [GUIDE] Debugging apps You'll definitely need that knowledge if you want to do serious Android development. The earlier you learn it the better. Good luck.
nikwen said:
The app crashs in line 77 of MainActivity. It's a NullPointerException.
Code:
boolean isGps = locationManager.isProviderEnabled("gps");
The reason for the crash is that in onCreate you commented this line out:
Code:
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Click to expand...
Click to collapse
Thanks, I remove by comment old controls and not noticed that comment also locationManager (!)
I correct; removed reference to commented controls and I don't have error but I can't see maps
Is "class MainActivity extends MapActivity" but np map, only lattice

[Q] how to start application on boot / startup

I tried to follow the tutorials on internet to start application start at boot time , but it does not seems to work.
i followed the tutorial, i also downloaded and installed this example source code, but this application wont work, its not showing at startup, is that something wrong with my device ? or is it has a technical changes like OS forbid it to run or something?
You need to create boot receiver:
public class BootExampleReciever extends BroadcastReceiver
{
@override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
you need to add the following permission to the manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
and to declare the receiver as well:
<receiver android:name=".BootExampleReciever">
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>

[Q] My android studio giving me errors and not working.

Well I posted it in android studio forum here but I don't know if it belongs to here..
any way -
READ ONLY EDIT DOWN!!
Okay, so I can't develop nothing as my Android Studio decided to. My all project is full of errors, unknown errors caused by Android Studio.
note: my files are correct, it is an other problem because even if I will import something from google codes it will have errors.
When I import a project everything's fine, but then after indexing and such things, all sudden everything is red and shouldn't be.
My errors for example are :
Code:
button1.setOnLongClickListener(new View.OnLongClickListener() {
....
....
}
Well shouldn't be error but :
Code:
cannot resolve symbol setOnLongClickListener
Another example:
Code:
button1=(Button) findViewById(R.id.button1);
I used this exact code for other button, seems right, I always using this line, it was fine until my Android Studio decided to give me some hard time, this line is full by errors and they are:
Code:
Unknown class: 'button1' , invalid method declaration; return type required, missing method body, or declare abstract
and there are like 20 errors that shouldn't be, things I tried:
1.deleting iml files , .idea folder - worked for a while but now it happened again and it doesn't fix it.
2.reinstalling android studio and then importing project.
3.upgrading android studio version to 1.3
4.restarting my pc.
5.importing project to an other pc, happened after a while.
6.Invalidate caches/ restart.
7.Changing module in project structure - I changed it back to how it was (it didn't help) and I think it caused the manifest error down..
My Module:app build.gradle:
Code:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "firstappdevelopments.david.reactiontime"
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
}
Also I noticed now, my Manifest file as an error in
Code:
android:name=".MainActivity"
says it has no default structure. something like this. here is the full normal code:
Code:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
</manifest>
Please, if someone knows what is the problem or what can I else do, just say, and I am sorry about my English, thank you all.
EDIT!!!:
I deleted this lines:
Code:
connect.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bluetooth = BluetoothAdapter.getDefaultAdapter();
if (bluetooth != null) {
if (bluetooth.isEnabled()) {
bluetooth.startDiscovery();
Set<BluetoothDevice> bondedSet = bluetooth.getBondedDevices();
if(bondedSet.size() > 0){
for(BluetoothDevice device : bondedSet){
newDevicesListView.setVisibility(View.VISIBLE);
mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
}
}else{
mArrayAdapter.add("No Devices");
}
}
} else {
textview.setText("bluetooth is disabled, enabling.");
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, RESULT_OK);
}
} else{
textview.setText("Bluetooth is not supported.");
}
}
});
AND SUDDENLY ALL THE ERRORS DISSAPPEARED , ANY IDEAS? - The errors was in other lines..
I dont understand the 2nd one but i cann help u in button prblm..
try this
Button button1 = (Button)findViewById(R.id.blahblah);
and button1.setOnLongClickListenetblahblahnla.......
try and let me know

App indexing: how to?

I'm implementing app indexing and I think I'm missing something, but I don't know what.
Following the guide I added my intent-filters to the app and implemented what's needed in my activity.
my application's package is com.towers.mypackage and the associated website (where I didn't put the link rel meta-tag yet, since I'm just testing) is www.mypackage.com
I saw the following intent-filter example in the guide
HTML:
<activity
android:name="com.example.android.PetstoreActivity"
android:label="@string/title_petstore">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="www.examplepetstore.com" />
</intent-filter>
</activity>
so I wrote mine in this way:
HTML:
<activity
android:name=".ActivityForAppIndexing"
android:label="@string/title_activity"
android:screenOrientation="portrait" >
<intent-filter android:label="@string/app_name">
<data android:scheme="android-app"
android:host="com.package.myappname" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http"
android:host="www.mywebsite.com" />
<data android:scheme="https"
android:host="www.mywebsite.com" />
</intent-filter>
</activity>
Also, I wrote a content provider in order to parse the URI
HTML:
<provider
android:name=".contentproviders.HotelDetailsContentProvider"
android:authorities="com.towers.mypackage" >
</provider>
which should map the URIs as follows:
Code:
private static final String BASE_PATH = "https";
private static final String AUTHORITY = "com.towers.mypackage";
public static final Uri CONTENT_URI = Uri.parse("android-app://" + AUTHORITY
+ "/" + BASE_PATH);
I'm testing the implementation via command line using the following adb command:
Code:
adb shell am start -a android.intent.action.VIEW -d "https://mypackage.com?hotel_id=135738" com.towers.mypackage
and IT WORKS. The app gets automatically opened with the right activity and the right parameters. When the app starts the onNewIntent method gets called:
Code:
protected void onNewIntent(Intent intent) {
String action = intent.getAction();
String data = intent.getDataString();
if (Intent.ACTION_VIEW.equals(action) && data != null) {
String recipeId = data.substring(data.lastIndexOf("/") + 1);
Uri contentUri = HotelDetailsContentProvider.CONTENT_URI.buildUpon()
.appendPath(recipeId).build();
bundle = new Bundle();
bundle.putString("pictureUrl", "");
//showRecipe(contentUri);
}
}
(I got it of course from the examples, that's why it talks about recipes)
But I wonder: what should I do? Get data from the intent with a
Code:
getIntent().getData().getQuery()
or use the ContentProvider and get them from the URI?
Also, I'd like to test with the Google Search Console and the "View as google" funcionality if everything is okay. I uploaded my APK and saw an URI is requested.
Now, in the "testing your app" section of the documentation I saw that the links like http://mypackage.com?hotel_id=135738 are referred as "deep links" while those like android-app://com.towers.mypackage/https/mypackage.com?hotel_id=135738 are referred as "URI". Am I right?
The "View as google" funcionality asks for a URI but I don't know how to create one. Also, I wonder how this URI is passed to the app and I'm pretty sure I'm getting very confused about this all URI/deepLink thing, and can't find relief in the documentation.
Where and when should I use the URI? Where and when should I use the deepLink? I guess that since I'm going to put the link rel=URI in my webpages then the app will be called in the app indexing with the URI and not with the URL of the page. But if it's so... why is the adb shell am start -a android.intent.action.VIEW -d command used for testing with the URL and not the URI? Should my app be able to get and handle URIs or URLs? And how?
I thought I had understood something about app indexing, but today I'm starting to think I got it all wrong since I started. That's why I ask you for help in answering the questions above, and possibly sheding a light on all this URL/URI/intent-filter/ContentProvider mess.
I already talked about this on Stackoverflow and got two answers, plus a lot of comments. But I wasn't able to get anything from that, App indexing remains a mysterious monster to me :-/
Did anyone of you manage to make this kind of things work? And how?
Thank you everybody, really.

Categories

Resources