android place picker or google maps api - android

i want to see all near places and use place picker for that, but when i start app picker appears and disappears, i cant understand why, help please, thx and sorry for my eng.
If you have some offers how i can see near places without picker, please tell me =)
UPD:
Tried change com.google.android.maps.v2.API_KEY on com.google.android.geo.API_KEY dont help.
MainActivity:
public class MainActivity extends AppCompatActivity {
private Button btPlacesAPI;
private TextView tvPlaceAPI;
private int PLACE_PICKER_REQUEST = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvPlaceAPI = (TextView) findViewById(R.id.tv_place_id);
btPlacesAPI = (Button)findViewById(R.id.bt_ppicker);
btPlacesAPI.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
try {
startActivityForResult(builder.build(MainActivity.this), PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(this,data);
String toastMsg = String.format(
"Place: %s \n" +
"Alamat: %s \n" +
"Latlng %s \n", place.getName(), place.getAddress(), place.getLatLng().latitude+" "+place.getLatLng().longitude);
tvPlaceAPI.setText(toastMsg);
}
}
}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ActivityMap"></activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAej54bA3F_PnWkVYX1XfKoEevcfC5RtXM" />
</application>

<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="Server_key" />
Key should be server key instead of android api key
refer this link http://www.androidrey.com/google-places-api-for-android-place-picker/

Related

Cannot activate my custom permission in my code

I want to ask users to agree with the disclaimer that I have provided in my application, and then if they agreed, next time they are using the app, we just re-show them the disclaimer for a few seconds without asking to click on anything and redirect them to the application. The best way I could have come up with it was, using a custom permission and however I did add permission commands to my manifest I could not figure out how to actually activate the permission in my code:
import java.util.jar.Manifest;
public class Language extends Activity {
Button engBut, fraBut;
// public static int j;
public void click (View view){
// j=1;
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
}
public void fraClick (View view){
// j=2;
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_language);
ImageView logo = (ImageView) findViewById(R.id.logo);
ImageView montfortLogo = (ImageView) findViewById(R.id.montfortLogo);
montfortLogo.setImageResource(R.drawable.k);
logo.setImageResource(R.drawable.j);
engBut = (Button) findViewById(R.id.engBut);
engBut.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(Language.this);
builder.setCancelable(true);
builder.setTitle("DISCLAIMER");
builder.setMessage(R.string.result_disclaimer);
builder.setNegativeButton("Get me out of here.", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
}
});
builder.setPositiveButton("I agree.", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
intent.setAction("com.techideas4you.pharamacy.MyAction");
intent.addCategory("android.intent.category.DEFAULT");
startActivity(intent);
}
});
builder.show();
}
});
fraBut = (Button) findViewById(R.id.fraBut);
Log.i("Locale", String.valueOf(Locale.getDefault()));
}
}
This was my first page code.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.ex"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE" />
<permission android:name="testDisclaimer" android:label="DISCLAIMER"
android:description="#string/result_disclaimer"/>
   
<uses-permission android:name="testDisclaimer"/>
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".MainActivity"
android:label="#string/app_name">
</activity>
<activity
android:name=".ActivityQuestion"
android:icon="#drawable/home"
android:label="Home"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".ActivityResult"
android:icon="#drawable/home"
android:label="Home"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity android:name=".Language">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter >
<action android:name="com.techideas4you.pharamacy.MyAction"
/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
and this is my manifest if anybody could help me out here I really appreciate it.
You have to add android:protectionLevel="dangerous" to the declaration of your permission else it will be granted automatically and users will not be presented with a dialog although you call requestPermission().
<permission android:name="your.package.name.permission.testDisclaimer" android:label="DISCLAIMER"
android:description="#string/result_disclaimer"
android:protectionLevel="dangerous"/>
<uses-permission android:name="your.package.name.permission.testDisclaimer"/>
In order to have the runtime show the disclaimer, you have to call
requestPermissions(new String[]{"your.package.name.permission.testDisclaimer"}, 42);
The result (whether user agreed) will be transmitted to you in onRequestPermissionsResult()
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults)
{
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 42 && grantResults != null){
Toast.makeText(this, "Permission " + permissions[0] + (grantResults[0] == PERMISSION_GRANTED ? "" : " NOT ") + " granted! ", Toast.LENGTH_LONG).show();
}
}
Please note that by using the permission system, you also have to cope with the fact that users will NOT be shown the permission-request-disguised-as-disclaimer if they
[...] turned down the permission request in the past and chose the
Don't ask again option in the permission request system dialog [...]
(quoted from documentation).
So maybe simply writing a flag to SharedPreferences will do the job just as well.

Intent Filter not working for Android Beam NFC

I am sure this is simple but I cannot figure it out. All I am trying to do is send a message via NFC (android Beam) and open my App on the receiver device. I did test my code on a new Project and it worked perfectly but if I try it on my real Project it just start "New Tag collected" and shows application/eu.freemoser.mydebts2go (see my screenshot). I don't know what's wrong maybe something with the manifest? The Google results doesn't match with my problem (or I am just to stupid) but I believe I found some related answer unfortunately I still was not able to solve my problem
My Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="eu.freemoser.myDebts2go"
android:versionCode="16"
android:versionName="1.1.0">
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-feature android:name="android.hardware.nfc" android:required="false" />
<uses-feature android:name="android.hardware.camera" />
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:name="eu.freemoser.myDebts2go.MyApplication"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Mydebts2go">
>
<service android:name="eu.freemoser.myDebts2goService.NotificationService"></service>
<service android:name="eu.freemoser.myDebts2goService.SynchronizationService"></service>
<service android:name="eu.freemoser.myDebts2goService.SynchronizService"></service>
<service android:name="eu.freemoser.myDebts2goService.AwesomeSynchronizService"></service>
<activity
android:name="eu.freemoser.myDebts2go.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="eu.freemoser.myDebts2GoActivities.AwesomeDetailActivity"
android:screenOrientation="portrait" android:theme="#style/Theme.MyDebts2GO.Detail">
</activity>
<activity android:name=".AndroidBeamActivity" android:screenOrientation="portrait"
android:theme="#android:style/Theme.DeviceDefault.Wallpaper.NoTitleBar">
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/eu.freemoser.myDebts2go" />
</intent-filter>
</activity>
<activity android:name="eu.freemoser.myDebts2GoActivities.DriveRestoreActivity"></activity>
<activity android:name="eu.freemoser.myDebts2GoActivities.SynchronizActivity"></activity>
<activity android:name="eu.freemoser.myDebts2GoActivities.SettingActivity">
<intent-filter>
<action android:name="android.intent.action.MANAGE_NETWORK_USAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="eu.freemoser.myDebts2GoActivities.DatePickerActivity"></activity>
<activity android:name="eu.freemoser.myDebts2GoActivities.LocationPickerActivity"></activity>
<activity android:name="eu.freemoser.myDebts2GoActivities.SearchActivity">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
</activity>
<activity
android:name="eu.freemoser.myDebts2GoActivities.DriveAuthorzingActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar">
</activity>
<activity
android:name="eu.freemoser.myDebts2GoActivities.FastModusShortcutActivity"
android:exported="true"
android:theme="#android:style/Theme.Holo.Light.NoActionBar">
</activity>
<!-- android:value="API_KEY" /> DEBUG-->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API_KEY" />
<meta-data
android:name="com.google.android.gms.version"
android:value="VERSION" />
</application>
</manifest>
The Fragment (sender)
public class AwesomeDetailFragment extends Fragment implements ObservableScrollView.Callbacks, NfcAdapter.CreateNdefMessageCallback, NfcAdapter.OnNdefPushCompleteCallback {
...
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
...
setUpAndroidBeam();
return mRootView;
}
private void setUpAndroidBeam() {
PackageManager pm = getActivity().getPackageManager();
// Check whether NFC is available on device
if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC)) {
// NFC is not available on the device.
}
// Check whether device is running Android 4.1 or higher
else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
// Android Beam feature is not supported.
} else {
myNfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
manageNfc();
}
}
private void manageNfc() {
if (myNfcAdapter != null) {
myNfcAdapter.setNdefPushMessageCallback(this, getActivity());
myNfcAdapter.setOnNdefPushCompleteCallback(this, getActivity());
}
}
...
#Override
public NdefMessage createNdefMessage(NfcEvent event) {
Time time = new Time();
time.setToNow();
String text = myBetrag + "//" + myTitle + "//" + myContactName + "//" + myStatus + "//" + myDebtDate + "//" + myCreateDate + "//" + myRemamberDate + "//" + myNote;
NdefMessage msg = new NdefMessage(
new NdefRecord[]{createMimeRecord(
"application/eu.freemoser.myDebts2go", text.getBytes())});
return msg;
}
public NdefRecord createMimeRecord(String mimeType, byte[] payload) {
byte[] mimeBytes = mimeType.getBytes(Charset.forName("US-ASCII"));
NdefRecord mimeRecord = new NdefRecord(
NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], payload);
return mimeRecord;
}
#Override
public void onNdefPushComplete(NfcEvent event) {
}
}
The Activity (receiver)
public class Beam extends Activity {
private Long userID = null;
private Long adressID = null;
private DBAdapter myDb;
//NFC
private String myBetrag;
private String myTitle;
private String myContactName;
private String myDebtDate;
private String myCreateDate;
private String myStatus;
private String myRemamberDate;
private String myNote;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
protected void onResume() {
super.onResume();
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
processIntent(getIntent());
}
}
void processIntent(Intent intent) {
myDb = new DBAdapter(this);
myDb.open();
Parcelable[] rawMsgs = intent.getParcelableArrayExtra(
NfcAdapter.EXTRA_NDEF_MESSAGES);
// only one message sent during the beam
NdefMessage msg = (NdefMessage) rawMsgs[0];
// record 0 contains the MIME type, record 1 is the AAR, if present
String temp = new String(msg.getRecords()[0].getPayload());
String[] arrrayTemp = temp.split("//");
try {
myBetrag = arrrayTemp[0];
myTitle = arrrayTemp[1];
myContactName = arrrayTemp[2];
myStatus = arrrayTemp[3];
myDebtDate = arrrayTemp[4];
myCreateDate = arrrayTemp[5];
// can be "NOT"
myRemamberDate = arrrayTemp[6];
myNote = arrrayTemp[7];
// checkValues
channgeStatus();
checkIfNot();
checkUser();
//write to database
write();
} catch (Exception ex) {
this.finish();
}
}
#Override
protected void onDestroy() {
super.onDestroy();
myDb.close();
}
private void checkUser() {
//do some stuff
...
}
private void write() {
//do some stuff
...
}
private void checkIfNot() {
//do some stuff
...
}
private void channgeStatus() {
//do some stuff
...
}
#Override
public void onNewIntent(Intent intent) {
// onResume gets called after this to handle the intent
setIntent(intent);
}
}
Android's MIME type matching for intent filters is case-sensitive (eventhough the MIME types themselves are not). Therefore, with Android (and also pretty much everywhere you use them) you should stick to the convention to use MIME types with lowercase letters only.
Specifically with MIME type records received over NFC, Android will automatically convert them to all-lowercase letters to overcome the problem of case-sensitivity in intent filters. So in your example, changing the type name in the intent filter to "application/eu.freemoser.mydebts2go" should work:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="application/eu.freemoser.mydebts2go"/>
</intent-filter>
In addition, you should also make sure you send the MIME type in lowercase letters only:
NdefMessage msg = new NdefMessage(
new NdefRecord[]{createMimeRecord(
"application/eu.freemoser.mydebts2go", text.getBytes())});

Pressing back button stops app during Camera activity

I capture photo and save into my Gallery. Everything works perfect when I capture an image and save. But if the camera is on and if I press the back button without taking a picture then the application stops.
How I can solve this issue?
This is my code:
public class ImportCard extends Activity {
private static final int CAMERA_PIC_REQUEST = 1111;
ImageButton importimage;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_import_card);
ImageButton importimage = (ImageButton) findViewById(R.id.importimage);
importimage.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA_PIC_REQUEST);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) {
//2
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
//3
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
//4
File file = new File(Environment.getExternalStorageDirectory()+File.separator + "image.jpg");
try {
file.createNewFile();
FileOutputStream fo = new FileOutputStream(file);
//5
fo.write(bytes.toByteArray());
fo.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Android Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapcard"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera"
android:required="true" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/vcard"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.mapcard.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.mapcard.Main"
android:label="#string/app_name" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.mapcard.NewCard"
android:label="#string/title_activity_new_card" >
</activity>
<activity
android:name="com.example.mapcard.ImportCard"
android:label="#string/title_activity_import_card">
</activity>
<activity
android:name="com.example.mapcard.CardBox"
android:label="#string/title_activity_card_box" >
</activity>
<activity
android:name="com.example.mapcard.QRCode"
android:label="#string/title_activity_new_card" >
</activity>
<activity
android:name="com.example.mapcard.Template"
android:label="#string/title_template" >
</activity>
<activity
android:name="com.example.mapcard.DisplayCard"
android:label="#string/title_display_card" >
</activity>
<activity
android:name="com.example.mapcard.GoogleMap"
android:label="#string/title_activity_google" >
</activity>
<activity
android:name="com.example.mapcard.ViewCard"
android:label="#string/title_view_card" >
</activity>
<activity
android:name="com.example.mapcard.QRScan"
android:label="#string/title_activity_import_card" >
</activity>
<activity
android:name="com.example.mapcard.ViewTemplates"
android:label="#string/title_view_templates" >
</activity>
<activity
android:name="com.example.mapcard.SendEmail"
android:label="#string/title_send_email" >
</activity>
</application>
Error in my LogCat:
java.lang.RuntimeException: Failure delivering result
Error on my device:
Unfortunately, App has stopped
You are checking only requestCode. You should check the value of resultCode also. When the user has successfully performed the action, the resultCode will be equal to RESULT_OK. If the user presses the back button then the resultCode will be RESULT_CANCELED. So your code must be modified like this.
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST && resultCode == RESULT_OK) {
//2
Add
android:noHistory="false"
in AndroidManifest.xml for that activity
In onActivityResult you should check whether thumbnail is null, and if so just return.
Edit: like this
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
...
Bundle extras = data.getExtras();
if (extras == null || extras.get("data") == null) return;
Bitmap thumbnail = (Bitmap) extras.get("data");
...
}
}

Android Start new activity first time

Android app issue:
I have MainActivity that when you press a button it opens the camera (an OCR) via Intent and startActivity. The problem is when I press the button in my mobile the first time after the installation, it gets blocked.
Then, after the first time, it works perfect...
By the way, when I try to execute the app in the android emulator it gives me only one error: "error opening trace file: No such file or directory" I don't know if this error is related with my problem in the mobile.
Here is the intent of MainActivity
Button2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
try {
Intent i = new Intent(getApplicationContext(), CaptureActivity.class);
startActivityForResult(i, REQUEST_CODE);
} catch (Exception e) {
}
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) {
if (data.hasExtra("ocrResult")) {
EditText.setText(data.getExtras().getString("ocrResult"));
} else if (resultCode == RESULT_CANCELED) {
}
}
}
And here you have the code of the OCR that sends the result to MainActivity
public void onClick(View v) {
finish();
}
public void finish() {
Intent data = new Intent();
data.putExtra("ocrResult", ocrResultView.getText());
setResult(RESULT_OK, data);
super.finish();
}
Finally, the manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.sfsu.cs.orange.ocr"
android:installLocation="auto"
android:versionName="0.5.13"
android:versionCode="32"
>
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="13"/>
<supports-screens android:xlargeScreens="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera.flash" android:required="false" />
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.screen.landscape"/>
<application android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
<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>
<activity android:name=".CaptureActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden"
>
</activity>
<activity android:name="edu.sfsu.cs.orange.ocr.PreferencesActivity"> </activity>
</application>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
</manifest>
Thank you very much!!

SipDemo's onReceive() SipAudioCall NullPointerException give

I am Creating incoming call Receive activity by SipDemo . My activity has two button "accept call" and "reject call". When i got incoming call then my own activity is open such as
----> incoming call class ----> onReceive()----> go to my call pick activity.
here is this above two button such as accept and reject call. but when i hit on "accept call" . A Nullpointer Exception generate. it is on SipAudiocall incoming;
this is incoming class:-
static SipAudioCall incomingCall = null;
#Override
public void onReceive(final Context context, Intent intent) {
Intent startActivity = new Intent();
startActivity.setClass(context, Mycall.class);
startActivity.setAction(IncomingCallReceiver.class.getName());
startActivity.setFlags(
Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
context.startActivity(startActivity);
}
public static void acceptCall() {
incomingCall.sendDtmf(9);
try {
incomingCall.sendDtmf(9);
incomingCall.answerCall(200);
//wtActivity.gototimer("i");
} catch (SipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// wtActivity.gototimer("i");
}
public void rejectCaLL() {
try {
incomingCall.endCall();
} catch (SipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
This is my call pick activity class:-
public class Mycall extends Activity {
Button acct;
IncomingCallReceiver incomingCallReceiver;
#Override
public void onCreate(Bundle savedInstanceState) {
// Note that none of the preferences are actually defined here.
// They're all in the XML file res/xml/preferences.xml.
super.onCreate(savedInstanceState);
setContentView(R.layout.my);
acct = (Button) findViewById(R.id.button1);
acct.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
IncomingCallReceiver.acceptCall();
}
});
}
}
This is AndroidManifest.xml :-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.sip">
<application android:icon="#drawable/icon" android:label="SipDemo">
<service android:name=".MService">
</service>
<activity android:name=".WalkieTalkieActivity"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".SipSettings" android:label="set_preferences"/>
<receiver android:name=".IncomingCallReceiver" android:enabled="true" android:label="Call Receiver">
<intent-filter>
<action android:name="android.SipDemo.INCOMING_CALL" />
</intent-filter>
</receiver>
<activity android:name=".Mycall"
>
</activity>
<activity android:name=".Myclass"/>
</application>
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.USE_SIP" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-feature android:name="android.hardware.sip.voip" android:required="true" />
<uses-feature android:name="android.hardware.wifi" android:required="true" />
<uses-feature android:name="android.hardware.microphone" android:required="true" />
Please Expert Help me. I has involved this problem since 1 month.
I am wait for your response.
Thank you
Becouse your
IncomingCallReceiver incomingCallReceiver;
is null at time of calling it...
If you create a static class you must take care to initiate it maybe in creator-method.
create an abstract class:
public abstract class IncomingCallReceiver
and change your method to public static final

Categories

Resources