groovy get attribute from AndroidManifest.xml - android

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.emnets.luoly.sample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="24"
android:targetSdkVersion="19" />
<uses-permission android:name= "android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name= "android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name="com.emnets.luoly.sample.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I would like to get uses-permission using groovy.
Maybe like this,
def manifestXml = new XmlParser().parse(Manifest)
manifestXml."uses-permission".each { p ->
println p.attribute("android:name")
}
How to get attribute like android.permission.WRITE_EXTERNAL_STORAGE

You can use XmlSlurper
def manifestXml = new XmlSlurper().parse(Manifest)
manifestXml."uses-permission".each { p ->
println p."#android:name"
}

Use XmlSlurper get ActivityName
def manifest = new XmlSlurper().parse(xmlFilePath)
String pkg = manifest.#package
manifest.application.activity.each {
String actName = it.'#android:name'
if (actName.substring(0, 1).equals('.')) {
actName = pkg + actName
}
println(actName)
}

Related

Android : Merging/concatenating two audio files hangs up the application

I'm appending two audio file using mp4parser. Appending is done but it is very slow don't know what is the issue.
On this line debugger stuck for big audio files for example approx 30 minutes audio file.
Container out = new DefaultMp4Builder().build(result);
Here is code.
Movie[] inMovies = null;
inMovies = new Movie[]{
MovieCreator.build(fileOne),
MovieCreator.build(fileTwo)};
List<Track> audioTracks = new LinkedList<Track>();
for (Movie m : inMovies) {
for (Track t : m.getTracks()) {
if (t.getHandler().equals("soun")) {
audioTracks.add(t);
}
}
}
Movie result = new Movie();
if (audioTracks.size() > 0) {
result.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
}
Container out = new DefaultMp4Builder().build(result);
String fileName = getFilename();
FileChannel fc = new RandomAccessFile(String.format(fileName), "rw").getChannel();
out.writeContainer(fc);
fc.close();
Manifestfile
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ehrlite"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ehr_icon"
android:label="#string/app_name"
android:name="com.webservice.myApplication"
android:theme="#style/AppTheme" >
<activity
android:name="com.ehrlite.LoginActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateVisible|adjustResize"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.ehrlite.MasterActivity"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.ehrlite.MainActivity"
android:screenOrientation="portrait"
>
</activity>
<activity
android:name="com.ehrlite.PrevMemo"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.webviewcall.WebViewActivity"
android:screenOrientation="portrait">
</activity>`enter code here`
<activity
android:name="com.ehrlite.TranscribedActivity"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:windowSoftInputMode="adjustPan">
</activity>
</application>
</manifest>
Can anyone help me out to improve performance,
thanks in advance.
I found the solution for your answer.
I was faced issue previously.
You are using RandomAccessfile. You need to use FileOutputStream
Container out = new DefaultMp4Builder().build(result);
String outputFilePath = getfilename();
FileOutputStream fos = new FileOutputStream(new File(outputFilePath));
out.writeContainer(fos.getChannel());
fos.close();
Reference:
why are java RandomAccessFile so much slower than FileOutputStream?

Didn't find class on path: DexPathList

I used a receiver in this code after running and receiving a sms this error is shown. I try some thing. I create new project and add file again. delete bin file. clean and restart project. but It doesn't solve the error. Is there anything that can solve this error. I really cant solved it.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="blocker.activity"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".FirstPage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".receiver.SMSReceiver" android:enabled="true">
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<activity
android:name=".Search"
android:label="#string/app_name" >
</activity>
<activity
android:name=".BlockActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name=".SmsFilter"
android:label="#string/app_name" >
</activity>
<activity
android:name=".CustomAdapter"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
error:
property:
the class for sms receiver:
public class SmsFilter extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
Bundle extras = intent.getExtras();
if (extras != null) {
Object[] pdus = (Object[])extras.get("pdus");
if (pdus.length < 1) return; // Invalid SMS. Not sure that it's possible.
StringBuilder sb = new StringBuilder();
String sender = null;
for (int i = 0; i < pdus.length; i++) {
SmsMessage message = SmsMessage.createFromPdu((byte[]) pdus[i]);
if (sender == null) sender = message.getOriginatingAddress();
String text = message.getMessageBody();
if (text != null) sb.append(text);
}
Log.i("LOG: ", "sms recived");
Log.i("LOG: ", sender);
if (sender != null && Search.search(sender)==true) {
abortBroadcast();
}
return;
}
}
// ...
}
}
Please check again the name of the receiver and the class name you declared in your manifest receiver.
In in java file the class name is-SmsFilter extends BroadcastReceiver
SmsFilter extends BroadcastReceiver
As you can see the name is SmsFilter but in your manifest file you are declaring it as SMSReceiver
The names are not matching. Edit your manifest to something like this-
<receiver android:name=".receiver.SmsFilter" android:enabled="true">
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
I hope it would help you..

Activity Not found Exception Cant figureout the error

Just started learning android app develpoment.
getting error "android.content.activitynotfoundexception no activity found"
Code:-
my Android Mainfest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gtctest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="14" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".SplashScreen"
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>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".StartingPointActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.GTC.STARTINGPOINTACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
and my Splash Screen.java
package com.example.gtctest;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class SplashScreen extends Activity {
#Override
protected void onCreate(Bundle splashBundle) {
// TODO Auto-generated method stub
super.onCreate(splashBundle);
setContentView(R.layout.splash);
Thread timer=new Thread() {
public void run() {
try {
sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Intent openStartingPointActivityIntent=new Intent("com.GTC.STARTINGPOINTACTIVITY");
startActivity(openStartingPointActivityIntent);
}
}
};
timer.start();
}
#Override
protected void onPause() {
super.onPause();
finish();
}
}
error:-
09-15 14:31:19.587: E/AndroidRuntime(1088): FATAL EXCEPTION: Thread-123
09-15 14:31:19.587: E/AndroidRuntime(1088): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.GTC.STARTINGPOINTACTIVITY }
09-15 14:31:19.587: E/AndroidRuntime(1088): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
09-15 14:31:19.587: E/AndroidRuntime(1088): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
09-15 14:31:19.587: E/AndroidRuntime(1088): at android.app.Activity.startActivityForResult(Activity.java:3190)
09-15 14:31:19.587: E/AndroidRuntime(1088): at android.app.Activity.startActivity(Activity.java:3297)
09-15 14:31:19.587: E/AndroidRuntime(1088): at com.example.gtctest.SplashScreen$1.run(SplashScreen.java:28)
Cant't figure out what is wrong.please help to solve this issue
And one more question
In android mainfest the name action name can be anything or it has to be path from package like "com.GTC.classname"
you have two application tags in your manifest. change it to one with both activities
please modify your manifest like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gtctest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="14" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".SplashScreen"
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=".StartingPointActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.GTC.STARTINGPOINTACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
ps: in android mainfest, the action name can be anything, but we used to make it like "com.xxx.intent.action.XXX".
Try this way,hope this will help you to solve your problem.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gtctest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="14" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".SplashScreen"
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>
<activity
android:name=".StartingPointActivity"
android:label="#string/app_name"/>
</manifest>
public class SplashScreen extends Activity {
#Override
protected void onCreate(Bundle splashBundle) {
// TODO Auto-generated method stub
super.onCreate(splashBundle);
setContentView(R.layout.splash);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(SplashScreen.this,StartingPointActivity.class);
startActivity(intent);
finish();
}
},3000);
}
#Override
protected void onPause() {
super.onPause();
}
}
Create Intent Like Following...
Intent intentname =new Intent(SplashScreen.this,StartingPointActivity.class);
startActivity(intentname);
Change in your AndroidManifest.xml File..
You have defined two <application> tag....
remove that and change it to following..
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gtctest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="14" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".SplashScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- add new activities like this -->
<activity
android:name=".StartingPointActivity"
android:label="#string/app_name" >
<!-- if your activity in different package you can define like this... (xx.xxx is your package name define your package name there..)
<activity
android:name="xx.xxx.StartingPointActivity"
android:label="#string/app_name" >
-->
</application>
</manifest>

java.lang.ClassCastException: android.app.Application cannot be cast to roboguice.application.RoboApplication

example using roboguice.
This code get ClassCastException.
public class MainActivity extends RoboActivity{
#InjectView(R.id.text)
TextView name;
#InjectView(R.id.imageView1)
ImageView imageView;
Drawable icon;
#InjectResource(R.string.app_name)
String myName;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
all jar files are already included.
My manifest.xml is here..
find this here.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.roboguice"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.roboguice.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>
</manifest>
no changes in manifest.xml.
if required then say.
Try this way
<application
android:name="roboguice.application.RoboApplication" // UPDATE HERE
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
Add this following line in application tag in AndroidManifest.xml
android:name="roboguice.application.RoboApplication"
#see [More details][1] http://code.google.com/p/roboguice/source/browse/roboguice/src/main/java/roboguice/application/RoboApplication.java?r=b6ae6aeaf9417826a2359fd779814af839557ca1

My updated SMS Receiver doesn't work Android

hi :) i'm working with SMS in android. i'm having problem with my sms receiver class. when i run my app for the first time on emulator, it works as i've programmed it to work. but when every time i run the app again, it doesn't work as i updated it to work. i'm stuck for last 2 days. can somebody plz guide me or provide some help. my basic receiver class is:
public class SMSreceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
String Sender = null;
String str = "";
SmsMessage [] msgs = null;
if(bundle != null)
{
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for(int i=0;i<msgs.length;i++)
{
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
Sender = msgs[i].getOriginatingAddress();
str = "SMS From: " + msgs[i].getOriginatingAddress();
str += ":";
str += msgs[i].getMessageBody().toString();
str += "\n";
}
//Toast.makeText(context, str, Toast.LENGTH_LONG).show();
Toast.makeText(context, Sender, Toast.LENGTH_LONG).show();
}
}
in above code, i've commented the toast that shows the msg, and tried to display the toast that shows the sender's number. but still it shows the new msg text. that's weird.
here's my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pingpongsmsremote"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="12" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.pingpongsmsremote.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="com.example.pingpongsmsremote.SMSScheduler"
android:label="#string/title_activity_smsscheduler" >
</activity>
<activity
android:name="com.example.pingpongsmsremote.FilterSMS"
android:label="#string/title_activity_filter_sms" >
</activity>
<activity
android:name="com.example.pingpongsmsremote.SMSRemote"
android:label="#string/title_activity_smsremote" >
</activity>
<activity
android:name="com.example.pingpongsmsremote.SendSms"
android:label="#string/title_activity_send_sms" >
</activity>
</application>
</manifest>
It looks like maybe you forgot to register the receiver? You need a line like this in your manifest:
<receiver android:name="SMSreceiver" >
<intent-filter>
<action android:name="android.provider.telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
To see it in a full manifest example would look like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pingpongsmsremote"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="12" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.pingpongsmsremote.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="com.example.pingpongsmsremote.SMSScheduler"
android:label="#string/title_activity_smsscheduler" >
</activity>
<activity
android:name="com.example.pingpongsmsremote.FilterSMS"
android:label="#string/title_activity_filter_sms" >
</activity>
<activity
android:name="com.example.pingpongsmsremote.SMSRemote"
android:label="#string/title_activity_smsremote" >
</activity>
<activity
android:name="com.example.pingpongsmsremote.SendSms"
android:label="#string/title_activity_send_sms" >
</activity>
<receiver android:name="SMSreceiver" >
<intent-filter>
<action android:name="android.provider.telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
</application>
</manifest>

Categories

Resources